I have a data set and I want to repeat a column value based on other column value,
my data look like read.table(text = "Year month flag 2001 1 Z 2001 2 - 2001 4 X 2002 1 Z 2002 2 - 2003 1 - 2003 2 Z 2004 2 Z 2005 3 Z 2005 2 - 2005 3 -", header = TRUE) Within year If flag = '-' then i want replace '-' by the previous row value of flag. In this example for yea 2001 in month 2 flag is '-' and I want replace it by the previous value of flag (i.e., 'Z') 2001 1 Z 2001 2 Z 2001 4 X If all values of flag are '-' within year then I wan to set as N The complete out put result will be year month flag 2001 1 Z 2001 2 z 2001 4 X 2002 1 Z 2002 2 Z 2003 1 Z 2003 2 Z 2004 2 Z 2005 3 Z 2005 2 N 2005 3 N Thank you in advance ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.