I'm having troube with an error in my script.
I have a data frame with the death_year column
(with values between 2000 and 2013) and I want to fill the cell of another column (year_X - being X a value between 2000 and 2013) with the value of 1 if the death_year == year_X
.
The outut would be something like this:
death_year year_2000 year_2001 year_2002
[1] 2000 1 0 0
[2] 2002 0 0 1
[3] 2009 0 0 0
That's my script:
a<-vector("numeric")
for(i in data$death_year){
for(j in 2000:2013){
if(i == j){
for(c in 1:length(data)){
data[c,paste( 'year', j, sep="" )]==1
}
}
}
Error in if (i == j) { : missing value where TRUE/FALSE needed
Can somebody help me?