[R] irregular splits in dataframe
    arun 
    smartpink111 at yahoo.com
       
    Tue Aug 21 12:45:22 CEST 2012
    
    
  
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.
    
    
More information about the R-help
mailing list