invalid factor level, NA generated when pasting in a dataframe in r -
i cannot paste correct data dataframe using rbind. here problem
results <- dataframe()
value store hospital name meets selection criteria , y[1,2] name of state
here when try past results blank dataframe results.
class(results) [1] "data.frame" value [1] "john c lincoln deer valley hospital" y[1,2] [1] "az" class(value) [1] "character" class(y[1,2]) [1] "character" results <- rbind(results,as.list(c(value,y[1,2]))) warning messages: 1: in `[<-.factor`(`*tmp*`, ri, value = "john c lincoln deer valley hospital") : invalid factor level, na generated 2: in `[<-.factor`(`*tmp*`, ri, value = "az") : invalid factor level, na generated results x.arkansas.methodist.medical.center. x.ar. 1 arkansas methodist medical center ar 2 <na> <na> 3 <na> <na>
how solve this? many thanks
you have factor when want character. str() on data frame identify columns factors suppose data.frame called mydf , factor columns columns 3 , 5
mydf[,c(3,5)] <- sapply(mydf[,c(3,5)],as.character)
Comments
Post a Comment