I'm getting the "names do not match previous names" error when merging 2 data frames. However, they both have exactly the same names. I put ** surrounding the two places where I define the data frames but they are identical. What is going on? Thanks!
Exact error: Error in match.names(clabs, names(xi)) : names do not match previous names
corr <- function(directory, threshold = 0) {
#store data frame that holds sulfate amount and nitrate amount that meet threshold and are complete cases
**data <- data.frame(sulfate = numeric(0), nitrate = numeric(0))**
#set working directory
setwd(directory)
#get file names
myfiles <- list.files(pattern = "csv")
#loop through files
for(i in 1:332) {
#read each file
current_dataset <- read.csv(myfiles[i])
#check if there are enough compelte cases to meet threshold
if(sum(complete.cases(current_dataset)) > threshold) {
#get complete cases
complete_cases <- current_dataset[complete.cases(current_dataset), ]
#add sulfate and nitrate info to table
**data <- rbind(data, data.frame(sulfate = complete_cases$sulfate[i], nitrate = complete_cases$nitrate)[i])**
}
}
#get correlation
cor(data)
}
data <- rbind(data, data.frame(sulfate = complete_cases$sulfate[i], nitrate = complete_cases$nitrate)[i])- userNaN