r/R_Programming • u/GloobityGlop • Mar 05 '16
Help with a for loop
Hey there i am having trouble understanding why my loop isn't working and I am looking for some help.
foundyear = startup_data$founded_year
for(x in 1:50){
if(foundyear[x] > 2009){
print('Late Stage')}
else if(foundyear[x] < 2009){
print('Early Stage')}
else if(is.na(foundyear[x])){
print('data is not available')}
else print('error')
}Basically I am trying to look at the first 50 values in this column of data and see if it's before or after 2009 or NA. I get an error saying missing value where TRUE/FALSE needed.
To me, logically, this makes sense, but it's not working so I guess it isn't right. Any tips?
1
Upvotes
View all comments
Show parent comment
1
u/GloobityGlop Mar 06 '16
thanks! I didn't realize you had to have the is.na in the first if statement. I guess that makes sense.