I have a table that for some variables has missing data (recorded as NULL) - I'd like to convert some of these missing cells to hold a 0 but for some reason I can't seem to get the syntax correct. My initial approach was to do this:
b<- eval(parse(text=paste(table_full$','column_name1',sep='')))
b[which(is.na(b))]<-0
b[which(b=='NULL')]<-0
and then save the data to a file, however - this still results in missing data in the output files and warning messages like:
In `[<-.factor`(`*tmp*`, which(is.na(b)), value = 0) :
invalid factor level, NA generated
Alternatively, I've tried things of the form:
b[which(is.na(as.numeric(as.character(b))))]<-0
but this didn't resolve the situation.
I'm relatively new to R and can't understand exactly what I'm doing wrong here. Thanks in advance!
is.na() returns TRUE or FALSE. Try b[which(is.na(b) == T)]<-0 instead