A QuiRk
September 18, 2010
So I’m working away in R on some analyses for the food safety folks at the BCCDC. I’ve written a nice little function that takes a data frame and an integer as its arguments and I want to loop through all the data frame / integer combinations.
for (i in integers){
for (frame in dataframes){
do function(frame, i)
}
}
No dice. I get the error “Error in frame$Variable : $ operator is invalid for atomic vectors”. Whaaat? Sure enough, looping through the data frames this way somehow causes them to be passed to the function as a set of vectors. I’m sure I’ll find a way to work around it, but I really don’t understand why it’s happening.
Advertisement