[R] replace

Val valkremk at gmail.com
Mon Mar 13 23:53:45 CET 2017


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

	[[alternative HTML version deleted]]



More information about the R-help mailing list