Re: [R] Repeat elements of matrix based on vector counts

2012-12-13 Thread arun
- Original Message - From: Sarah Haas To: r-help@r-project.org Cc: Sent: Thursday, December 13, 2012 9:15 AM Subject: [R] Repeat elements of matrix based on vector counts I have two dataframes (df) that share a column header ("plot.id").  In the 1st df, "plot.id" recor

Re: [R] Repeat elements of matrix based on vector counts

2012-12-13 Thread Rui Barradas
Hello, Something like this? rep(df2$load, table(df1$plot.id)) Hope this helps, Rui Barradas Em 13-12-2012 14:15, Sarah Haas escreveu: I have two dataframes (df) that share a column header ("plot.id"). In the 1st df, "plot.id" records are repeated a variable number of times based on the numb

Re: [R] Repeat elements of matrix based on vector counts

2012-12-13 Thread Sarah Goslee
Hi Sarah, If I understand your requirements correctly, the easiest thing to do is approach it from a different direction: df3a <- merge(df1, df2) But you can also use rep for this simple example because plot.id in df2 is sorted: nindex <- table(df1$plot.id) df3b <- df2[rep(1:length(nindex), times

[R] Repeat elements of matrix based on vector counts

2012-12-13 Thread Sarah Haas
I have two dataframes (df) that share a column header ("plot.id"). In the 1st df, "plot.id" records are repeated a variable number of times based on the number of trees monitored within each plot. The 2nd df only has a single record for each "plot.id", and contains a variable named "load" that is