I have a set of imported CSV files stored under the variable name data. The imported files are of different lengths and I would like to be able to discard the ones below a certain length.

I believe that Mathematica has a Select[] function that might be right for this, but I haven't been able to manage it yet. My elementary attempt looks like this, but it returns a set of empty sets.

newdata = Table[Select[data[[i]], Length[data[[i]]] > 47], {i, 1, Length[data]}]

Any help would be appreciated, thanks!

  • $\begingroup$ Does each entry of data the entire csv file as an unparsed string?, i.e. data[[1]] is like "col1,col2,...\ndata11,data12,...\ndata21,data22,...\n..." $\endgroup$ – user13892 Sep 26 '19 at 13:11

The following can be used if the csv files are imported as strings.

Select automatically iterates over a List of data.

So given a data like this

data = RandomWord["CommonWords", 10]

The following will select the data of more than a certain length:

Select[data, StringLength[#] > 7 &]

If the data is already parsed like

Dimensions /@ data

then you can use the following to select those with more than 15 rows of data

newdata=Select[data, Length[#]>15 &];
Dimensions /@ newdata

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.