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

[R-Forge #5070] lapply "[" without anonymous function #500

Closed
arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Closed

[R-Forge #5070] lapply "[" without anonymous function #500

arunsrinivasan opened this issue Jun 8, 2014 · 0 comments
Assignees
Labels

Comments

@arunsrinivasan
Copy link
Member

Submitted by: Garrett See; Assigned to: Nobody; R-Forge link

From an e-mail to the list

I have a list of data.tables and I am trying to extract a subset from each of them. I can achieve what I want with this:

L <- list(data.table(BOD), data.table(BOD))
lapply(L, function(x) x[Time==3L])
# [[1]]
#    Time demand
#1:    3     19
# 
# [[2]]
#    Time demand
#1:    3     19

However, I'd rather not type have to create an anonymous function. I tried the below, but [.data.frame is being dispatched.

lapply(L, "[", Time==3L)
# Error in `[.data.frame`(x, i) : object 'Time' not found

Even if I am explicit, [.data.table does not get dispatched:

lapply(L, data.table:::`[.data.table`, Time==3L)
# Error in `[.data.frame`(x, i) : object 'Time' not found
@arunsrinivasan arunsrinivasan self-assigned this Aug 3, 2014
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

1 participant