Kevin Wright
2009-Oct-30 20:25 UTC
[R] What should my.data.frame[c(3, 1)] <- list(NULL, NULL) evaluate to?
(R 2.9.2 on Windows XP) Turns out that my.data.frame[c(1,3)] <- list(NULL, NULL) and my.data.frame[c(3,1)] <- list(NULL, NULL) are not the same. Is this expected? Example: d0 <- structure(list(Year = c(2009L, 2009L, 2009L), Season = c(1L, 1L, 1L), Series = c(1L, 1L, 1L), Mst = structure(c(1L, 1L, 1L), .Label = "", class = "factor"), Yield = structure(c(1L, 1L, 1L), .Label = "", class = "factor")), .Names = c("Year", "Season", "Series", "Mst", "Yield"), row.names = c(NA, 3L), class = "data.frame") d1 <- d0 d1[c(3,1)] <- list(1:3, 4:6) print(d1) Year Season Series Mst Yield 1 4 1 1 2 5 1 2 3 6 1 3 d1[c(3,1)] <- list(NULL, NULL) print(d1) Season Series Yield 1 1 1 2 1 2 3 1 3 It appears that the above assignment deletes column 1 from the data frame, then sequentially deletes column 3 (Mst, which was originally column 4 before column 1 was deleted). Compare this to d1 <- d0 d1[c(1,3)] <- list(NULL, NULL) print(d1) Season Mst Yield 1 1 2 1 3 1 Kevin Wright [[alternative HTML version deleted]]