我创建了以下功能
FilterIndi <- function(infile,name, date){
sub_file <- infile[,c("NUMBER","CREATE_DTTM_NEW", name)]
sub_file <- subset(sub_file, name==1)
library(data.table)
sub_file <- setDT(sub_file)[, .SD[which.max(CREATE_DTTM_NEW)], NUMBER]
sub_file$date <- sub_file$CREATE_DTTM_NEW
sub_file$CREATE_DTTM_NEW <- NULL
library(dplyr) #to do left_join
Unique <- left_join(Unique,sub_file, by =c("NUMBER"="NUMBER"))
Unique$name[is.na(Unique$name)] <-0
return(Unique)
}
FilterIndi(allfile,pde,pde_date)
pde在dataframe allfile中,但是我收到以下错误:
Error in `[.data.frame`(infile, c("NUMBER", "CREATE_DTTM_NEW", :
object 'pde' not found
我无法弄清楚如何让它发挥作用。有人可以帮帮我吗?非常感谢提前。 编辑:我附上了allfile的图像