[R] Split Strings

Miluji Sb milujisb at gmail.com
Sun Jan 17 21:56:18 CET 2016


I have a list of strings of different lengths and would like to split each
string by underscore "_"

pc_m2_45_ssp3_wheat
pc_m2_45_ssp3_wheat
ssp3_maize
m2_wheat

I would like to separate each part of the string into different columns
such as

pc m2 45 ssp3 wheat

But because of the different lengths - I would like NA in the columns for
the variables have fewer parts such as

NA NA NA m2 wheat

I have tried unlist(strsplit(x, "_")) to split, it works for one variable
but not for the list - gives me "non-character argument" error. I would
highly appreciate any help. Thank you!

	[[alternative HTML version deleted]]



More information about the R-help mailing list