1

I have a CSV with 22 cols, within each cell is complied data eg(1,2,3,4,5,6,7,8,9,10,11,12.) sep by commas. Installing the stringr package I can use the str_split_fixed() function to my data.

I can perform

str_split_fixed(a$col_1, “,”,12)

to split a single col, but I want to apply this function to all columns of CSV to save typing out the above code 22 times... Any help is much appreciated

e.matt
  • 836
  • 1
  • 5
  • 12
  • What are you doing with these values after you split them? And the columns of your CSV file are separated by commas, but your fields also have comma separators? I would be helpful in include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions – MrFlick Mar 06 '18 at 17:08
  • How do you want to arrange them? In a list form? In a table? etc – Onyambu Mar 06 '18 at 17:31
  • Table form so then I can output to a new CSV – e.matt Mar 06 '18 at 17:59

1 Answers1

0

The apply family of functions will apply across a dataset:

lapply(a,function(x) str_split_fixed(x, “,”,12))

will return a list with the results of splitting each column in a separate list object.

Pdubbs
  • 1,967
  • 2
  • 11
  • 20