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

bug? rbindlist idcol constructed incorrectly #1432

Closed
franknarf1 opened this issue Nov 11, 2015 · 2 comments
Closed

bug? rbindlist idcol constructed incorrectly #1432

franknarf1 opened this issue Nov 11, 2015 · 2 comments
Labels
Milestone

Comments

@franknarf1
Copy link
Contributor

Looking at this SO question

# http://stackoverflow.com/questions/33661645/r-number-of-non-na-records-by-column-grouped
list_1 <- list(a = c(44,47), dens = c(2331,1644))
list_2 <- list(a=66, dens= 1890)
list_3 <- list(a=c(44,46,48,50), dens=c(8000,1452,1596,7521)) 
mylist <- list(list_1, list_2, list_3)
names(mylist)<-c("ID_1","ID_2","ID_3")

I thought I could use rbindlist, but

rbindlist(mylist, id=TRUE)

    .id  a dens
1: ID_1 44 2331
2: ID_1 47 1644
3: ID_2 66 1890
4: ID_2 44 8000
5: ID_3 46 1452
6: ID_3 48 1596
7: ID_1 50 7521
Warning message:
In set(ans, j = idcol, value = rep.int(nm, len)) :
  Supplied 6 items to be assigned to 7 items of column '.id' (recycled leaving remainder of 1 items).

As suggested by the warning, the final .id is wrong. I see the same warning with various subsets of mylist.

By the way, the "How to file a bug report" link is still dead over here: https://github.com/Rdatatable/data.table/blob/master/Contributing.md

@franknarf1
Copy link
Contributor Author

Looking at the code for rbindlist, I think I found the problem:

vapply(mylist, NROW, 0L)
# 2 2 2

where we need 2 1 4. To get the latter, vapply(lapply(mylist, setDT), NROW, 0L) works, but alters the input. I'm sure you guys know a better way to do it.

@eantonya
Copy link
Contributor

maybe vapply(l, function(x) length(x[[1]]), 0L)?

On Wed, Nov 11, 2015 at 5:52 PM, franknarf1 notifications@github.com
wrote:

Looking at the code for rbindlist, I think I found the problem:

vapply(mylist, NROW, 0L)

2 2 2

where we need 2 1 4. To get the latter, vapply(lapply(mylist, setDT),
nrow, 0L) works, but alters the input. I'm sure you guys know a better
way to do it.


Reply to this email directly or view it on GitHub
#1432 (comment)
.

@arunsrinivasan arunsrinivasan added this to the v1.9.8 milestone Nov 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants