Re: [R] paste function by INDICES

2011-04-27 Thread Phil Spector
Massimiliano - Here's one way, assuming you wanted b to be the same length as a: df = transform(df,b=ave(as.character(df$a),df$ID, FUN=function(a)paste(a,collapse=''))) If you just want one observation for each value of ID, you could use aggregate(df$a,list(ID=df$ID),

[R] paste function by INDICES

2011-04-27 Thread Massimiliano Tripoli
Dear all, I have the following R dataframe: set.seed(11) (df <- data.frame(ID=rep(1:10,1:10),a=factor(sample(1:4,55,rep=T)))) where ID is an identification code. I need to create a new variable "b" in which I would paste the full group of "a" variable according to ID variable. F