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
\\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
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
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
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
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
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
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)
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
9 matches
Mail list logo