[R] Combining series of variables using identifier

2008-02-26 Thread Lauri Nikkinen
R users, I have df like this a - data.frame(indx =1:20, var1 =rep(c(I20, I40, A50, B60), each=5), var1_lab= rep(c(cat, dog, mouse, horse), each=5), var2 =rep(c(B20, X40, D50, G60), each=5), var2_lab=

Re: [R] Combining series of variables using identifier

2008-02-26 Thread K. Elo
Hi, if the columns always follow the same order (indx,var#, var#_lab ...), then You could use the column numbers and do the following: 1) CN-colnames(df)[#] (#=colnum of 'var#') 2) df$NEW-(here the expression to create the new variable) 3) colnames(df)[ncol(df)]-c(paste(CN,new,sep=_)) This can