0
$\begingroup$

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!

$\endgroup$
1
  • $\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
    Commented Sep 26, 2019 at 13:11

1 Answer 1

1
$\begingroup$

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

data=Table[Table[RandomWord["CommonWords",5],RandomInteger[{10,20}]],{20}];
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
$\endgroup$

Your Answer

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

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