ってFAQに書いてあるのを毎回忘れるのでメモ。
In R, if
xis a list, thenx[i] <- NULLandx[[i]] <- NULLremove the specified elements fromx. The first of these is incompatible with S, where it is a no-op. (Note that you can set elements toNULLusingx[i] <- list(NULL).) (https://cran.r-project.org/doc/FAQ/R-FAQ.html#Others)
x <- list(i = 1, j = 2) x["i"] <- NULL x #> $j #> [1] 2 x <- list(i = 1, j = 2) x["i"] <- list(NULL) x #> $i #> NULL #> #> $j #> [1] 2
これがx[[i]] <- list(NULL)とかx$i <- list(NULL)だと、NULLではなくlist(NULL)が代入されるので注意。