简体   繁体   中英

R - how to find max date in R using sqldf

资料图片

Getting all corresponding rows after group by with max date?

I have csv file as

a = read.csv(file = "a.csv", header = TRUE, sep = ",")

My code:

b = sqldf("Select psno , Field_description , log_new_value , MAX 
        (inserted_on) from a group by psno having log_new_value = 'Yes'")

But it's giving the wrong answer?

Any experts can help me solving this please? Thanks.

Most likely, the INSERTED_ON column is a character vector rather than some kind of date-time object.

Try converting them as follows first before calculating the maximum:

a$INSERTED_ON <- as.POSIXct(a$INSERTED_ON, format=c("%m/%d/%Y %H:%M"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM