Message-ID: <1345545922.32525.YahooMailNeo@web142601.mail.bf1.yahoo.com>
Date: 2012-08-21T10:45:22Z
From: arun
Subject: irregular splits in dataframe
In-Reply-To: <1345528488.6601.YahooMailNeo@web125204.mail.ne1.yahoo.com>
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,`[`,1)),col2=do.call(rbind,lapply(dat3,`[`,2)))
# ? ? ? ? ? ? ? ? ? ? ? ? ?col1??????????????????????? col2
#1????? Granitic Hills 16-20 PZ??????????????????????? <NA>
#2??????? Loamy Upland 16-20 PZ??????????????????????? <NA>
#3? Sandy Loam Upland 12-16 PZ??? Sandy Loam, Deep 12-16 PZ
#4?????? Loamy Upland 12-16 PZ?? Sandy Loam Upland 12-16 PZ
#5??????? Loamy Upland 16-20 PZ??????????????????????? <NA>?
A.K.
----- Original Message -----
From: Sapana Lohani <lohani.sapana at ymail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Tuesday, August 21, 2012 1:54 AM
Subject: [R] irregular splits in dataframe
Hello everyone,
My dataframe (Soil Type) looks something like this
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
I want to separate them at "/", but when there is just one type, I want "NA" in the second column, How can I do that ??
Thank you
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.