Re: [R] splits with 0s in middle columns

2012-09-02 Thread arun
it(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. Fr

Re: [R] splits with 0s in middle columns

2012-09-02 Thread arun
\\1 \\2 \\3 \\4",B))) dat1<-data.frame(do.call(rbind,strsplit(C," "))) colnames(dat1)<-paste0("A",1:4) dat1 }  fun1(A) #  A1 A2 A3 A4 #1 10 20  0 30 #2 40  0  0 20 #3 60 10 10  5 #4 80  0  0 10 A.K. - Original Message - From: Rui Barradas To: Sapana Lohani

Re: [R] splits with 0s in middle columns

2012-09-02 Thread Rui Barradas
the whole column I wanted to split. Could you please have a look and suggest me the error? I ma totally stuck at this point of my analysis From: Rui Barradas To: Sapana Lohani Cc: r-help Sent: Sunday, September 2, 2012 10:05 AM Subject: Re: [R] splits w

Re: [R] splits with 0s in middle columns

2012-09-02 Thread Rui Barradas
Hello, You don't need a new function, what you need is to prepare your data in such a way that the function can process it. A <- c("percent (10/20/30)", "percent (40/20)", "percent (60/10/10/5)", "percent (80/10)") B <- gsub("\\(|\\)|percent| ", "", A) fun(B) Also, please use dput to post th

Re: [R] splits with 0s in middle columns

2012-08-31 Thread arun
t;,1:4)  dat3 #  A1 A2 A3 A4 #1 10 20  0 30 #2 40  0  0 20 #3 60 10 10  5 #4 80  0  0 10 A.K. - Original Message - From: Sapana Lohani To: R help Cc: Sent: Friday, August 31, 2012 12:10 PM Subject: [R] splits with 0s in middle columns Hi, A column of my df looks like A 10/20/30

Re: [R] splits with 0s in middle columns

2012-08-31 Thread arun
t;,"\\1 \\2 \\3 \\4",dat1$V1))) dat3<-data.frame(do.call(rbind,strsplit(dat2, " ")))  colnames(dat3)<-paste0("A",1:4)  dat3 #  A1 A2 A3 A4 #1 10 20  0 30 #2 40  0  0 20 #3 60 10 10  5 #4 80  0  0 10 A.K. - Original Message ----- From: Sapana Lohani To: R he

Re: [R] splits with 0s in middle columns

2012-08-31 Thread Rui Barradas
age in the code you sent. It says "Error in fun(A) : could not find function "paste0" I am a new in R so could not fix it. Can you help me fix that ? Thanks From: Rui Barradas To: Sapana Lohani Cc: r-help Sent: Friday, August 31, 2012 12:35

Re: [R] splits with 0s in middle columns

2012-08-31 Thread Rui Barradas
Hello, Try the following. A <- c( "10/20/30", "40/20", "60/10/10/5", "80/10") fun <- function(X){ xname <- deparse(substitute(X)) s <- strsplit(X, "/") n <- max(sapply(s, length)) tmp <- numeric(n) f <- function(x){ x <- as.numeric(x) m <- length(x)

[R] splits with 0s in middle columns

2012-08-31 Thread Sapana Lohani
Hi, A column of my df looks like A 10/20/30 40/20 60/10/10/5 80/10 I want to split it such that the last column has the last composition and if there are not enough the middle columns get the 0s. That way my df would look like A1 A2 A3 A4 10 20 0 30 40 0 0 20 60 10 10 5 80 0 0 10 How can I