2

I have a huge list, ex. {a,b,c},{d,e,f} and I must have only {a,c},{d,f}. I using import from url. My sentence:

Drop[Import["url"],{2}] 

And it doesn't work. Why?

  • why do you need the `Import[]`? You can use only the list as argument. Also, look at the manual for `Drop`: it says it deletes the first n elements. If you use `Drop[yourlist,2]` you will be deleting the first 2 elements of `yourlist`. Have a look into `Delete[]`, maybe this is what you want – Sos Jul 24 '13 at 13:49
  • You could also try importing just the columns of interest. For example: `Import["URL", {"Data", {All}, {1, 3}}];` (See [here](http://mathematica.stackexchange.com/a/5921/106)) – 681234 Jul 26 '13 at 14:50
  • Please consider using the dedicated SE site for *Mathematica*: http://mathematica.stackexchange.com – Mr.Wizard Jul 26 '13 at 21:53

2 Answers2

10

Just use the third parameter of the Drop function, like so:

list = {{a, b, c}, {d, e, f}};
Drop[list, None, {2}]

This will return:

{{a, c}, {d, f}}
Mr Alpha
  • 1,813
  • 1
  • 16
  • 26
2

You need to map drop over the list.

list = {{a, b, c}, {d, e, f}};
Map[Drop[#, {2}] &, list]

{{a, c}, {d, f}}

Alternatively, use transpose, but this is apparently less efficient because it makes copies of the list.

Transpose@Drop[Transpose@list, {2}]
Chris Degnen
  • 8,443
  • 2
  • 23
  • 40