Leftjoin not working inside a function

I am trying to use leftjoin inside a function that used a list of dataframes.
I got error saying no applicable method for 'left_join' applied to an object of class "list",
My code is given below:

df1 <- data.frame(A = 1, B = 2)
df2 <- data.frame(X = 2, Y = 2)
df_final <- list(df1,df2)
colnames <- c("sl","name") 
df_final=lapply(df_final, setNames, colnames)
df3 <- data.frame(A = 1, B = 2)
df4 <- data.frame(X = 2, Y = 2)
df_final2 <- list(df3,df4)
colnames=c("sl","add")
df_final2=lapply(df_final2, setNames, colnames)
datalist=function(oberved, simulated){
  df=left_join(oberved, simulated, by = 'sl')
  return(df)
}
f=datalist(df_final,df_final2)

Thanks

What is your expected output? In dplyr, left_join works for tibbles or dataframe. But you provided lists as input. Thanks

Thank you @mhakanda for youre reply.
I got the solution by using

f=parallel::mcmapply (function(oberved, simulated){
  return(datalist(oberved, simulated))
}, df_final, df_final2,mc.cores=1,SIMPLIFY = FALSE)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.