Cannot assign columns as.Date by reference in data.table [duplicate]
Duplicate: This is a duplicate of this question I'm assigning a new column as Date or IDate while using by =. It's creating an integer column, not a Date as expected. require(data.table) dt <- data.table(date = as.IDate(sample(10000:11000, 10), origin = "1970-01-01")) dt[, group := rep(1:2, 5)] print(dt) # date group # 1: 1997-06-12 1 # 2: 1998-02-19 2 # 3: 1998-04-25 1 # 4: 1998-01-27 2 # 5: 1997-10-29 1 # 6: 1998-05-08 2 # 7: 1999-05-09 1 # 8: 1999-06-26 2 # 9: 1997-11-01 1 # 10: 1997-07-19 2 This works: dt[, min.date := min(date)] print(dt) # date group min.date # 1: 1997-06-12 1 1997-06-12
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.