I try to create a list of data on which I can perfrom a function. But I have problems in getting the data from my Excel sheet. My Excel sheet looks like this:

      x1 y[1,1] y[1,2] y[1,3] y[1,4] .... y[1,200]
      x2 y[2,1] y[2,2] y[2,3] y[2,4] .... y[2,200]
      xn ..

now I would like to get a list

      { {data1}, {data2}, {data3}, ... {data200}}


      data1 = {{x1,y[1,1]},{x2,y[2,1]},..}
      data2 = {{x1,y[1,2]},{x2,y[2,2]},..}
      and so on

Can anyone give me an advice how to do it? Thanks a lot Walter

  • $\begingroup$ Did you check Import (and possibly the "Table" option)? $\endgroup$ – anderstood Mar 14 '17 at 14:44
  • $\begingroup$ @anderstood thanks, but how can I make the list by mapping it with a rule. The x value is the first column and always the same for the different y-values, which are in separate columns $\endgroup$ – Walter Schrabmair Mar 14 '17 at 14:54
  • $\begingroup$ If you managed to import the data, then your question is about rearranging the imported list and you should probably rewrite your question which is not related to importing nor excel. $\endgroup$ – anderstood Mar 14 '17 at 15:10
  • $\begingroup$ @anderstood thanks I found it: `Table[{s[[i, 1]], s[[1, j]]}, {i, 1, Length[s]}, {j, 2, Length[First@s]}] ' $\endgroup$ – Walter Schrabmair Mar 14 '17 at 15:18

I am not sure if I understand your question. Say you have imported the following structure:

 import = {{x1, y[1, 1], y[1, 2], y[1, 3]}, {x2, y[2, 1], y[2, 2], y[2, 3]}}

Then, it would probably be more appropriate to save new lists in data[1], data[2], etc. rather than data1, data2, etc. This is how it could be done:

Table[data[i - 1] = 
   Transpose@{import[[All, 1]], import[[All, i]]}, {i, 2, Length@Transpose@import}]


 data[1] (* {{x1, y[1, 1]}, {x2, y[2, 1]}} *)
 data[2] (* {{x1, y[1, 2]}, {x2, y[2, 2]}} *)

If you really need data1, data2, etc. let me know and I'll add a suggestion.

  • $\begingroup$ Thanks a lot, your solution is much more sophisticated $\endgroup$ – Walter Schrabmair Mar 14 '17 at 15:19
  • $\begingroup$ @WalterSchrabmair Still, you can improve your question to help future users. $\endgroup$ – anderstood Mar 14 '17 at 15:33

Given @anderstood's data structure, another way, if you really want to learn about some List Manipulation functions:

data = Transpose[Map[Thread[List[First[#], Rest[#]]&, import]]

The trick here is using List[...] as the function getting threaded between the First element and the list of the Rest of the elements. Map is just the iteration through each row.

Also, this would normally be written like this, where /@ is infix shorthand for Map:

data = Thread[{First[#], Rest[#]}]& /@ import // Transpose
  • $\begingroup$ I am not home to test this for syntax issues, so please help out and correct me :^) I'll check it myself later. $\endgroup$ – Andrew Cheong Mar 14 '17 at 15:22
  • 1
    $\begingroup$ I tested, I think you mean data = Transpose@Map[Thread[List[First[#], Rest[#]]] &, import] (added one closing bracket + Transpose). As per the second line, I think you should add // Transpose afterwards. $\endgroup$ – anderstood Mar 14 '17 at 15:30
  • $\begingroup$ Ah, thank you @anderson! Will fix. $\endgroup$ – Andrew Cheong Mar 14 '17 at 15:34
  • $\begingroup$ @AndrewCheong Thanks that was I was wanted to learn, and now I can apply my function to this list of datas, I think by f @@@ {data} $\endgroup$ – Walter Schrabmair Mar 14 '17 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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