In the following example, how can I drop the group index from the list after I perform a split? n <- 3 nn <- 10 g <- factor(round(n * runif(n * nn))) x <- rnorm(n * nn) + sqrt(as.numeric(g)) df <- data.frame(g,x) df.s <- split(df,g) Thanks! Rick DeShon [[alternative HTML version deleted]]
Did not completely understand what is a 'group index', but to remove any element from a list or a matrix, or a vector or a data frame you could use the negative index. For example,> df.s[-c(1:3)]$`3` g x 1 3 3.916503 12 3 1.435718 24 3 2.252151> df.s[-c(1:3)][[1]][-1]x 1 3.916503 12 1.435718 24 2.252151 You can also assign the results to a variable (the same or the other one)> df.s<-df.s[-c(1:3)][[1]][-1] > df.sx 1 3.916503 12 1.435718 24 2.252151 Rick DeShon wrote:> > In the following example, how can I drop the group index from the list > after > I perform a split? > n <- 3 > nn <- 10 > g <- factor(round(n * runif(n * nn))) > x <- rnorm(n * nn) + sqrt(as.numeric(g)) > df <- data.frame(g,x) > df.s <- split(df,g) >-- View this message in context: http://www.nabble.com/How-to-remove-index-from-list-after-split--tf4441712.html#a12673118 Sent from the R help mailing list archive at Nabble.com.
Wayne.W.Jones at shell.com
2007-Sep-14 11:16 UTC
[R] How to remove index from list after split?
Not sure what you mean by "group index" but try:
lapply(df.s,function(l){l$x})
or something like:
do.call("rbind",df.s)
to convert the result into a data.frame.
Regards
Wayne
-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org]On Behalf Of Rick DeShon
Sent: 14 September 2007 11:50
To: r-help at stat.math.ethz.ch
Subject: [R] How to remove index from list after split?
In the following example, how can I drop the group index from the list after
I perform a split?
n <- 3
nn <- 10
g <- factor(round(n * runif(n * nn)))
x <- rnorm(n * nn) + sqrt(as.numeric(g))
df <- data.frame(g,x)
df.s <- split(df,g)
Thanks!
Rick DeShon
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.