[R] Prefix

Val valkremk at gmail.com
Mon Nov 9 01:05:18 CET 2015

HI all,

DF <- read.table(textConnection(" X1   X2 X3   TIME
Alex1      0         0       1960
Alexa      0         0        1920
Abbot      0         0          0
Smith     Alex1  Alexa    2012
Carla     Alex1      0        1996
Jacky    Smith   Abbot    2013
Jack       0         Jacky    2014
Almo     Jack     Carla     2015   "),header = TRUE)

I want to add the time  variable as prefix to the first column  (X1)
and I did it as follow,

DF$X4 <- as.character(paste(DF$TIME,DF$X1 ,sep="_"))

All names in column two (X1) and three  (X3) are in column one. so I just
want bring that prefix to column three and two, as well but I could not do
that one.

Here is the final output  that  I would like to have.

              X1                   X2                     X3
1960_Alex                      0                       0
1920_Alexa                     0                      0
 0_Abbot                          0                      0
2012_Smith     1960_Alex     1920_Alexa
1996_Carla      1960_Alex                     0
 2013_Jacky    2012_Smith         0_Abbot
 2014_Jack                       0      2013_Jacky
 2015_Almo        2014_Jack      1996_Carla

Your help is appreciated in advance

	[[alternative HTML version deleted]]

More information about the R-help mailing list