Please help me understand how the ... arguments works in a function. I am trying to input values into my function such as the following:
test_data<-function(data, ...){
pr <- list(...)
nm <- names(data)
for(i in seq_along(nm)){
if(pr == nm[i]) nm<-(nm[-i])
}
return(nm)
}
This should pass any value to the dots and check if the name matches it, if it does then remove the name from the names of the data. However, when I do this I get the following:
test_data(mtcars, 'carb')
>NULL
I should get:
[1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec"
[8] "vs" "am" "gear"
test_data(mtcars, 'carb'), I had insteadtest_data(data, 'carb'), and so it returnedNULL. It does work but the answer is definitely much cleaner!