New to R Studio. I'm trying to read in excel file names and populate a data.frame:
#Let's say I've already read in a file name
counter <- 1 #simplifying as this would be a for loop that would start with a counter at 1
file_name <- "excel file name"
extension <- "xlsx"
status <-"successful"
#I initialize the data.frame and label the columns
global_file_list <- data.frame(File.Name = as.character(),
Extension = as.character(),
Status = as.character())
#When I try to populate this first row, I get the following warnings and the data.frame remains empty:
global_file_list[counter,] <- data.frame(cbind(file_name, extension, status))
Warning messages:
1: In [<-.factor
(*tmp*
, iseq, value = c(file_name = 1L)) :
invalid factor level, NA generated
2: In [<-.factor
(*tmp*
, iseq, value = c(file_ext = 1L)) :
invalid factor level, NA generated
3: In [<-.factor
(*tmp*
, iseq, value = c(status = 1L)) :
invalid factor level, NA generated
#However, if I were to do the following, without using the counter, the first row populates:
global_file_list <- data.frame(cbind(file_name, extension, status))
#Then this continues to work but populates the dataframe with N/A values
counter <- counter + 1
global_file_list[counter,] <- data.frame(cbind(file_name, extension, status))
- What is the reason the dataframe won't accept the first entry with a counter?
- Why does it populate with N/A instead of my variable values?
Thanks for your help!