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
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
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,
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)
##
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
5 matches
Mail list logo