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 it be possible to use .N in column names? #1582

Closed
DavidArenburg opened this issue Mar 8, 2016 · 3 comments
Closed

Should it be possible to use .N in column names? #1582

DavidArenburg opened this issue Mar 8, 2016 · 3 comments

Comments

@DavidArenburg
Copy link
Member

library(data.table) #v1.9.6
DT <- fread("user_id  date  weight
12345    2016-03-07    160
12345    2016-03-06    158
12345    2016-03-05    156
12345    2016-03-04    154")

I'm not sure why I can't just do

DT[, paste0("weight_", 1:.N) := shift(weight, 1:.N)]
# Error in 1:.N : argument of length 0

Instead of

DT[, paste0("weight_", 1:nrow(DT)) := shift(weight, 1:.N)]

Is that a bug or I simply don't understand how .N works?

Motivation: http://stackoverflow.com/questions/35855934/using-dplyrmutate-to-apply-parameterizations-of-a-function-to-a-single-data-fr?noredirect=1

@arunsrinivasan
Copy link
Member

No. only on the RHS. But maybe we can get this to work.

@MichaelChirico
Copy link
Member

Related #1543

@MichaelChirico
Copy link
Member

I think subsumed by #581

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants