-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Row operations in data.table using by = .I
#1732
Comments
Alternatively, Similar issue with using |
Why not just add feature "rowwise" by using |
Hi @leoluyi , the behaviour of |
Thank you all. This is extremely helpful ! I may have found a small bug though.
|
Both work for me on library(data.table)
dt = data.table(V0 =LETTERS[c(1,1,2,2,3)], V1=1:5, V2=3:7, V3=5:1)
dt[, sum(.SD[, -1, with=FALSE]), by = .I]
#> I V1
#> <int> <int>
#> 1: 1 9
#> 2: 2 10
#> 3: 3 11
#> 4: 4 12
#> 5: 5 13
dt[, sd(.SD[, -1, with=FALSE]), by = .I]
#> I V1
#> <int> <num>
#> 1: 1 2.000000
#> 2: 2 1.154701
#> 3: 3 1.154701
#> 4: 4 2.000000
#> 5: 5 3.055050 What's your output for |
Oh, I thought this was already implemented in version |
I was exploring alternatives of how to do row operations in
data.table
and I think I've found a bug.These three lines of code should return the same result. However, the result of
by = .I
seems return a wrong result.dt[, sdd := sum(.SD[, 2:4, with=FALSE]), by = 1:NROW(dt) ]
dt[, rowpos := .I][ , sdd := sd(.SD[, -1, with=FALSE]), by = rowpos ]
dt[ , sdd := sd(.SD[, -1, with=FALSE]), by = .I ]
sample data:
dt <- data.table(V0 =LETTERS[c(1,1,2,2,3)], V1=1:5, V2=3:7, V3=5:1)
The text was updated successfully, but these errors were encountered: