1
$\begingroup$

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?

$\endgroup$
1
  • 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$ Jun 4, 2013 at 19:58

1 Answer 1

7
$\begingroup$

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"}}
$\endgroup$
1
  • $\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$
    – Alex
    Jun 4, 2013 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.