I have a function which takes a vector of .txt files names of a directory and converts them to a data frame:
makeList <- function(x) {
print(x)
dataList <- jsonlite::fromJSON(x)
dataTemp <- as.data.frame(dataList, stringsAsFactors = FALSE)
data <- select(dataTemp, -hit_lats, -hit_lngs)
return(data)
}
I applied this function to name of files:
DF <- lapply(filenames, FUN = makeList)
and finally, bind the resulted list to a data frame:
dFinal <- data.frame()
for(i in 1:length(DF)){
dFinal <- rbind(dFinal, DF[[i]])
}
when I do not use stringsAsFactors = FALSE
in as.data.frame
I give some warnnings like:
Warning messages:
1: In `[<-.factor`(`*tmp*`, ri, value = c(5.53719008264463, ... :
invalid factor level, NA generated
2: In `[<-.factor`(`*tmp*`, ri, value = c(1.....
...
but my main problem is that in my data frame two of variables become totally NA. However, I checked this process for some single files (not by the function) and I had not any NA (obviously, I do not run the last part of the code for a single file).
Does anybody know why these NAs have generated?