I am trying to import data from Excel. It is located in a single column of the Excel file but each cell contains a comma separated pair of two values as a,b. When I am importing them I have this format {{"a,b"},{"c,d"},...,{"x,y"}, which means just one element not a pair of numbers. How can I have {{a,b},{c,d},...,{x,y}} instead?
-
2$\begingroup$ For this specific problem chuy's answer below seems appropriate, but I feel that your actual problem is a botched import in Excel, probably of some kind of CSV file. You probably needed to import that using Excel's import wizard. $\endgroup$– Sjoerd C. de VriesJun 4, 2013 at 19:58
1 Answer
You can use Apply
and StringSplit
to help out:
rawData = {{"a,b"}, {"c,d"}, {"e,f"}};
Apply[StringSplit[#, ","] &, rawData, {1}]
(*output in InputForm to show structure more clearly*)
{{"a", "b"}, {"c", "d"}, {"e", "f"}}
-
$\begingroup$ many thanks!! if I want in this form of
{{a
, b},{c
, d`},...} ,how can I do that?(it is in input form).I mean all just digit. $\endgroup$– AlexJun 4, 2013 at 17:45