0

I have created the following function

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 is in data frame allfile but I get the following error:

Error in '[.data.frame'(infile, c("NUMBER", "CREATE_DTTM_NEW", : object 'pde' not found

I can't figure out how to make it work.

Can someone please help me? Thanks a lot in advance. EDIT: I have attached an image of allfile:

enter image description here

Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
baver
  • 23
  • 1
  • 6
  • 1
    Your question is difficult to troubleshoot, it is not [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Please provide *sample* output of your variables (`allfile`, `pde`, and `pde_date`). (I suspect that `pde` is a *field within `allfile`*, which means you likely need to quote it, as in `FilterIndi(allfile, "pde", ...)`, but that's complete speculation.) – r2evans Apr 27 '17 at 16:23
  • Hi, I have added an image of allfile. You are right. pde is a field in allfile. – baver Apr 28 '17 at 08:29
  • 1
    Please do not include an image of data: who wants to transcribe data? What you did took more effort than posting just the data itself, the link suggested using `dput(allfile)` or (if large) `dput(head(allfile))` (did you read the link?). Finally, what happened when you tried to quote the second argument as I suggested previously? – r2evans Apr 28 '17 at 13:48

0 Answers0