My RAM is 4 GB and I am using a 64-bit Windows and R. I want to merge around 25 data frames on the basis of common key column (Date). I searched on internet and and various forums of stack overflow. However, I am getting the error "Error: cannot allocate vector of size x Gb ". The data.frames looks like
A <- data_frame(Date = c("1/1/1990","1/2/1990","1/3/1990"), MXAR = c(342.369,342.369,525.528 ))
B <- data_frame(Date = c("11/30/2009","12/1/2009","12/2/2009"), MXBD = c(1000,1007.13,998.55 ))
C <- data_frame(Date = c("6/1/2005","6/2/2005","6/6/2005"), MXBH = c(1209.21,1205.74,1195.33 ))
I have around 25 data.frames like A, B and C (each having around 3000 rows). I am using the solutions available as shown below on stack overflow. A, B and C data.frames shows NA's in the last rows. However, they keep on throwing errors. Kindly help. filenames=list.files(path=path, full.names=TRUE)# files are type of A, B and C #discussed above
datalist = lapply(filenames, function(x){read_excel(x,sheet=1)})
df6<-datalist %>% Reduce(function(dtf1,dtf2) inner_join(dtf1,dtf2,by="Date"), .)
and
file_list <- list.files()
for (file in file_list)
{
# if the merged dataset does exist, append to it
if (exists("dataset")){
temp_dataset <-read_excel(file)
dataset<-merge.data.frame(dataset, temp_dataset, by=c('Date'))
rm(temp_dataset)
}
# if the merged dataset doesn't exist, create it
if (!exists("dataset")){
dataset <- read_excel(file)
}
}
and
reshape::merge_all(datalist, by="Date")
When running
datalist = lapply(filenames, function(x){data.table(read_excel(x,sheet=1), key="Date")})
The program throws many warnings like
In read_xlsx_(path, sheet, col_names = col_names, col_types = col_types, ... :
[1601, 1]: expecting date: got '[NULL]'
A, B and C data.frames shows NA's in the last rows. Is there way to remove these NA's in the above lines of code and then running the program. May that removes errors.