I'm using the below syntax to gather all files in a folder, read them, and merge based on common columns.
allData <- list.files(path="/Users/me/Desktop/Holder", full.names = TRUE) %>%
lapply(read_csv) %>%
bind_rows
However, in some of my files, a certain column has NAs. Thus, it won't merge and I get the following error:
Error: Can't combine `..1$D_postIAT` <double> and `..2$D_postIAT` <character>.
How can I get around this?
...I tried to create an example with syntax, but it's hard for me to reproduce:
a<-t(c(123, 456, 789))
a<-as.data.frame(a)
b<-t(c(987, NA, 654))
b<-as.data.frame(b)
#b[1,2]<-as.logical(b[1,2])
b[1,2]<-as.character(b[1,2])
^I first tried to make the NA a logical value, but that didn't work. I could make it a character though.
c<-as.list(c(a,b))
bind_rows(c)
^the bind_rows didn't work, because the columns had the same name, but I thought that's how it knows what to bind?
d<-NA
as.data.frame(d)
b[1,2]<-d
^When I tried to create a logical vlaue for NA, it converted back to numeric after I added it to b.