[R] replicating dataframe rows

David Huffer David.Huffer at csosa.gov
Mon Sep 29 22:56:18 CEST 2008


On Monday, September 29, 2008 1:59, Dimitris Rizopoulos wrote:
 > On Monday, September 29, 2008 1:26, milton ruser wrote:
 > > ...I  have  a  data.frame  like...
 > >    place<-c("place1", "place2", "place3", "place4", "place5")
 > >    population<-c(100,200,300,50,30)
 > >    my.df<-data.frame(cbind(place,population))
 > > ...and I would like to expand my  data.frame
 > > using  "population"  variable.  So, for each
 > > line of my data.frame I would like that  the
 > > new  data.frame  have  many  rows   as   the
 > > population collumn...
 > ...try this...
 >    place <- c("place1", "place2", "place3", "place4", "place5")
 >    population <- c(100, 200, 300, 50, 30)
 >    my.df <- data.frame(place, population)

Or...

place <- c("place1", "place2", "place3", "place4", "place5")
population <- c(100, 200, 300, 50, 30)
my.df <- data.frame(place, population)

my.df [
  rep ( row.names ( my.df )
  , as.numeric ( as.character ( my.df$population ) )  
  ) ,
]
 
--
 David



More information about the R-help mailing list