Skip to content
Prev 304715 / 398506 Next

splits with 0s in middle columns

Hi,
It's working for me.
Try this:
dat1<-read.csv("test.csv")
dat2<-na.omit(dat1)
?
nrow(dat1)
#[1] 635
?nrow(dat2)
#[1] 627

B<-gsub(" slope{0,1}\\s\\((.*)\\)","\\1",dat2$Composition_percent_part)
fun1<-function(x){
C<-gsub("(.*)/(.*)","\\1 0 0 \\2", gsub("(.*)/(.*)/(.*)","\\1 \\2 0 \\3", gsub("(.*)/(.*)/(.*)/(.*)","\\1 \\2 \\3 \\4",x)))
res<-data.frame(do.call(rbind,strsplit(C," ")))
colnames(res)<-paste("A",1:4,sep="")
res
}
fun1(B)
head(fun1(B),15)
?#? A1 A2 A3 A4
#1? 60 25? 0 15
#2? 60 25? 0 15
#3? 40 35 15 10
#4? 40 35 15 10
#5? 40 35 15 10
#6? 40 35 15 10
#7? 40 35 15 10
#8? 50 40? 0 10
#9? 50 40? 0 10
#10 50 40? 0 10
#11 50 40? 0 10
#12 50 30? 0 20
#13 50 30? 0 20
#14 50 30? 0 20
#15 50 30? 0 20

#or,
fun1<-function(x){
B<-gsub(" slope{0,1}\\s\\((.*)\\)","\\1",x)
C<-gsub("(.*)/(.*)","\\1 0 0 \\2", gsub("(.*)/(.*)/(.*)","\\1 \\2 0 \\3", gsub("(.*)/(.*)/(.*)/(.*)","\\1 \\2 \\3 \\4",B)))
res<-data.frame(do.call(rbind,strsplit(C," ")))
colnames(res)<-paste("A",1:4,sep="")
res
}
fun1(dat2$Composition_percent_part)??? 


?head(fun1(dat2$Composition_percent_part),5)
#? A1 A2 A3 A4
#1 60 25? 0 15
#2 60 25? 0 15
#3 40 35 15 10
#4 40 35 15 10
#5 40 35 15 10



A.K.
Message-ID: <1346636960.99910.YahooMailNeo@web142606.mail.bf1.yahoo.com>
In-Reply-To: <1346632757.43122.YahooMailNeo@web125205.mail.ne1.yahoo.com>