Say we have a data.table
myDT <- data.table(id = c("a", "a", "b", "b", "c"), value = 1:5)
setkey(myDT, id)
I'd like to create a function
fun <- function(id) {
...
}
such that if
foo <- rep("b", 6)
then
fun(foo)
# I want this to return 3 4
Basically, I want to pass id[[1]] from the execution environment to the i argument of myDT.
I'm having a really hard time accessing the correct environment here and am looking for some help.
Changing the name of the function argument is not an option.
foo = c("a","b")what result do you want?foois always of the formrep(x ,n)wherex\inletters