Why can't I assign a value to an entire column of a data frame, and then one item in the same βinsideβ statement? Code:
foo <- data.frame( a=seq(1,10) ) foo <- within(foo, { b <- 1
gives:
abc 1 1 1 1 2 2 20 20 3 3 1 1 4 4 1 20 5 5 1 1 6 6 1 20 7 7 1 1 8 8 1 20 9 9 1 1 10 10 1 20
The value of b is what I expected. The value of c is strange. It seems that I am doing what I expect if the assignment to the entire column (ie b <-1) is in a different expression "inside" than assignment to one element (ie b [2] <- 20 ) But not if they are in the same "inside."
Is this a mistake or something that I just don't understand about R?
source share