ALSE)
d
Da: "Bert Gunter"
A: "Massimo Bressan"
Cc: "r-help"
Inviato: Martedì, 12 giugno 2018 16:42:18
Oggetto: Re: [R] extract and re-arrange components of data frame
You mean like this?
> s.new <-with(d, as.numeric(unlist(strsplit(s,","
&
> #I need to get this final result
> r<-data.frame(i=c(1,1,1,2,2,3), s=c(97, 98, 99, 103, 105, 118))
Nothing magic to suggest.
But maybe:
list.s <- strsplit(d$s,",")
r <- data.frame(i=rep(d$i, times=sapply(list.s, length)), s=unlist(list.s),
stringsAsFactors=FALSE )
S Ellison
**
You mean like this?
> s.new <-with(d, as.numeric(unlist(strsplit(s,","
> s.new <- cut(s.new,breaks = c(0,100,110,200),lab = d$i)
> s.new
[1] 1 1 1 2 2 3
Levels: 1 2 3
(Obviously, this could be a one-liner)
See ?cut
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is th
# considering this data.frame as a reproducible example
d<-data.frame(i=c(1,2,3), s=c('97,98,99','103,105', '118'), stringsAsFactors =
FALSE)
d
#I need to get this final result
r<-data.frame(i=c(1,1,1,2,2,3), s=c(97, 98, 99, 103, 105, 118))
r
#this is my attempt
#number of components for
4 matches
Mail list logo