[R] flag a record
Ashta
sewashm at gmail.com
Sun Feb 28 03:23:36 CET 2016
Hi all,
I have a data set represented by the following sample.
I want flag records of an individual as "N", if if the tag column of
an individual is equal to zero for the last two years. So in the
following example, Alex1 records are flagged as "y", On the other
hand Carla's records are flagged as "N" because all values of tag for
Carla are zero. Another typical example is that Jon, although the tag
values of Jon are greater than 0 it is flagged as "N", because his
record are more than two years old.
DF <- read.table(textConnection(" Name year tag
Alex1 2011 0
Alex1 2012 1
Alex1 2013 0
Alex1 2014 1
Carla 2013 0
Carla 2014 0
Carla 2015 0
Carla 2012 0
Tom 2014 1
Tom 2015 1
Jon 2010 1
Jon 2011 1 "),header = TRUE)
I want create another variable " Flag with value Y or N" if an
individual has a value greater than 0 in the tag column for the last
two years then the flag value will be y otherwise it n.
the outcome will be
name year tag Flag
Alex1 2011 0 y
Alex1 2012 1 y
Alex1 2013 0 y
Alex1 2014 1 y
Carla 2013 0 n
Carla 2014 0 n
Carla 2015 0 n
Carla 2012 0 n
Tom 2014 1 y
Tom 2015 1 y
Jon 2010 1 n
Jon 2011 1 n
Thank you in advance
More information about the R-help
mailing list