Re: [R] Conditional extraction of values in a data.frame in r

2021-04-22 Thread Jim Lemon
Hi Marna, This may be what you want: get_latest<-function(x,format="%m/%d/%Y") { x<-unlist(x) x[nchar(x)==0]<-NA if(all(is.na(x))) return(NA) else return(format(max(as.Date(x,format),na.rm=TRUE),format)) } daT$output1<-apply(daT[,2:4],1,get_latest) The empty value in daT gave a bit of trouble

[R] Conditional extraction of values in a data.frame in r

2021-04-22 Thread Marna Wagley
Hi R Users, I have been struggling to extract the data based on conditional values in different columns. I have a very big dataset (rows) and a couple of columns. here an example of the dataset is: daT<-structure(list(ID = c("id1", "id2", "id3", "id4", "id5", "id6", "id7"), First_detectiondate =