-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
project.org] On Behalf Of arun
Sent: Friday, August 17, 2012 6:56 AM
To: Sapana Lohani
Cc: R help
Subject: Re: [R] Unequal splits from a column
HI,
Try this:
dat1<-data.frame(slope=c("slope (60/25/15)","slope (90/10)","slope
(40/35/15/10)","slope (40/25/25/10)" ))
dat1$slope<-gsub("slope\\s+.*(\\(.*\\))","\\1",dat1$slope)
?dat1$slope<-gsub("\\((.*)\\)","\\1",dat1$slope)
dat2<-strsplit(dat1$slope,"/")
dat2[[1]][4]<-0
dat2[[2]][3:4]<-0
data.frame(do.call(rbind,dat2))
#? X1 X2 X3 X4
#1 60 25 15? 0
#2 90 10? 0? 0
#3 40 35 15 10
#4 40 25 25 10
----- 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: Friday, August 17, 2012 1:05 AM
Subject: [R] Unequal splits from a column
Hi I am new to R so am struggling with the commands here
I have one column in a table that looks like
slope (60/25/15)
slope (90/10)
slope (40/35/15/10)
slope (40/25/25/10)
I want to have 4 columns with just the number inside the parenthesis.
when there is no number that cell can have 0. I want the output like
this
60 25 15 0
90 10 0 0
40 35 15 10
40 25 25 10
Can somebody help me??
Thanks
??? [[alternative HTML version deleted]]