Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:= should as.POSIXct when RHS is POSIXlt #1724

Closed
linzhp opened this issue May 26, 2016 · 5 comments · Fixed by #6299
Closed

:= should as.POSIXct when RHS is POSIXlt #1724

linzhp opened this issue May 26, 2016 · 5 comments · Fixed by #6299
Labels

Comments

@linzhp
Copy link

linzhp commented May 26, 2016

I am able to add a POSIXct column to a data.frame, but not data.table.

data <- read.table(header=TRUE, text='
 id weight
  1     20
  2     27
  3     24
')
dates <- c(strptime('160523-1600', '%y%m%d-%H%M'),strptime('160523-1600', '%y%m%d-%H%M'),strptime('160523-1600', '%y%m%d-%H%M'))
dt <- data.table(data)
# This works well
data$dates <- dates
# This results in an error
dt$dates <- dates

The error message I get is:

Warning message:
In [<-.data.table(x, j = name, value = value) :
Supplied 11 items to be assigned to 3 items of column 'dates' (8 unused)

And the dates field is not properly assigned to dt.

@franknarf1
Copy link
Contributor

franknarf1 commented May 26, 2016

I think the recommended way is

dt[, dates := as.POSIXct(dates)]

I think data.table doesn't like POSIXlt cols, judging by dt[, .(dates)] giving

Error in setDT(jval) :
Column 1 is of POSIXlt type. Please convert it to POSIXct using as.POSIXct and run setDT again. We do not recommend use of POSIXlt at all because it uses 40 bytes to store one date.

You might also want to check out ?IDateTime.

@arunsrinivasan
Copy link
Member

I could have sworn that I fixed dt[, date := dates] to automatically convert to POSIXct and issue a warning..

@linzhp linzhp changed the title Not able to add POSIXct column Not able to add POSIXlt column May 26, 2016
@linzhp
Copy link
Author

linzhp commented May 26, 2016

I am using version 1.9.6, and dt[, date := dates] still gives me an error. Was the fix made after 1.9.6?

@arunsrinivasan
Copy link
Member

arunsrinivasan commented May 26, 2016

What I meant was dt[, date := dates] doesn't seem to be working as intended.

@pseemakurthi
Copy link

pseemakurthi commented May 31, 2016

Date col is being converted as a number when writing the file to disc using fwrite()
I'm not sure if someone already reported the above bug

Version : : R 3.3.0
data.table 1.9.7

@MichaelChirico MichaelChirico changed the title Not able to add POSIXlt column := should as.POSIXct when RHS is POSIXlt May 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants