Skip to content
Prev 367718 / 398500 Next

replace

Val
HI all,

if first name  is  Alex then I want concatenate the second column to Alex
to produce Alex and  the second column value

DF1 <- read.table(header=TRUE, text='first YR
Alex    2001
Bob     2001
Cory    2001
Cory    2002
Bob     2002
Bob     2003
Alex    2002
Alex    2003
Alex    2004')


Output
data frame
DF2
Alex-2001   2001
Bob             2001
Cory            2001
Cory            2002
Bob             2002
Bob             2003
Alex-2002   2002
Alex-2003   2003
Alex-2004   2004

I tried this one but did not work.
DF1$first[DF1$first=="Alex"] <-  paste(DF1$first, DF1$YR, sep='-')

Thank you in advance