Re: [R] Irregular splits in dataframe

2012-08-21 Thread David Winsemius
On Aug 21, 2012, at 3:24 PM, Sapana Lohani wrote: Hello, Re framing my previous question, my dataframe (Soil Type) looks something like below. I want the code to find "/" first and split the string into 2 or 3 depending on the number of "/". I don't want to specify the number of column

Re: [R] irregular splits in dataframe

2012-08-21 Thread arun
Hi, Slight modification to my earlier code to make it more simple. dat1 <- readLines(textConnection("Granitic Hills 16-20 PZ  Loamy Upland 16-20 PZ  Sandy Loam Upland 12-16 PZ / Sandy Loam, Deep 12-16 PZ  Loamy Upland 12-16 PZ / Sandy Loam Upland 12-16 PZ  Loamy Upland 16-20 PZ")) dat3<-strspli

Re: [R] irregular splits in dataframe

2012-08-21 Thread arun
Hi, Try this: dat1 <- readLines(textConnection("Granitic Hills 16-20 PZ  Loamy Upland 16-20 PZ  Sandy Loam Upland 12-16 PZ / Sandy Loam, Deep 12-16 PZ  Loamy Upland 12-16 PZ / Sandy Loam Upland 12-16 PZ  Loamy Upland 16-20 PZ"))  dat3<-strsplit(dat1,"/")  data.frame(col1=do.call(rbind,lapply(dat3,

Re: [R] irregular splits in dataframe

2012-08-21 Thread Noia Raindrops
How about this? read.table(text = "Granitic Hills 16-20 PZ Loamy Upland 16-20 PZ Sandy Loam Upland 12-16 PZ / Sandy Loam, Deep 12-16 PZ Loamy Upland 12-16 PZ / Sandy Loam Upland 12-16 PZ Loamy Upland 16-20 PZ", header = FALSE, sep = "/", fill = TRUE, na.strings = "", strip.white = TRUE) ##

Re: [R] irregular splits in dataframe

2012-08-21 Thread jim holtman
try this: > x <- scan(text = "Granitic Hills 16-20 PZ + Loamy Upland 16-20 PZ + Sandy Loam Upland 12-16 PZ / Sandy Loam, Deep 12-16 PZ + Loamy Upland 12-16 PZ / Sandy Loam Upland 12-16 PZ + Loamy Upland 16-20 PZ", what = '', sep = '\n') Read 5 items > x [1] "Granitic Hills 16-20 PZ" [2] "Loamy Up