Skip to content
Prev 275213 / 398513 Next

Expanding rows of a data frame into multiple rows

To further  Weidong Gu's suggestion merge would give you what you want but not the numeric column corresponding to the sector.  Adding that would be easy enough via transform if you really desired it.
 
Tyler

 
obs.l<-sapply(input$observations,length) 
desire.output<-data.frame(site=rep(1:6,obs.l),obs=unlist(input$observations))
merge(input[,-3], desire.output, all.x=TRUE)
----------------------------------------