Here's another approach using the plyr package:
# Function to process each row of input:
g <- function(d) {
y <- unlist(d$observations)
if(length(y) > 0)
data.frame(site = d$site, sector = d$sector, y = y) else NULL
}
library('plyr')
> ddply(input, .(site), g)
site sector y
1
s.com
> Subject: Re: [R] Expanding rows of a data frame into multiple rows
>
> This may work
>
> obs.l<-sapply(input$observations,length)
>
> desire.output<-data.frame(site=rep(1:6,obs.l),obs=unlist(input$observations))
>
> Weidong Gu
>
> On Sat, Oct 22, 2011
This may work
obs.l<-sapply(input$observations,length)
desire.output<-data.frame(site=rep(1:6,obs.l),obs=unlist(input$observations))
Weidong Gu
On Sat, Oct 22, 2011 at 7:51 PM, Peter Meilstrup
wrote:
> The setup: I have a data frame where one column is in list mode, and
> each entry contains a
The setup: I have a data frame where one column is in list mode, and
each entry contains a vector of varying length.
I want to expand this into a data frame with one row for each member
of the list-mode column (the other values being replicated)
For example, an example input and the desired output
4 matches
Mail list logo