Sometimes I come across this instance in R:
L <- list()
L[[1]] <- list()
L[[2]] <- list()
L[[1]][[1]] <- 1
L[[1]][[2]] <- 2
L[[2]][[1]] <- 1
L[[2]][[2]] <- 2
Then I want to name all elements of the nested lists in L
the same. I usually do something like this:
L <- lapply(L, function(x){names(x) <- c("One", "Two"); x})
However, this looks kind of awful and I'm sure there has to be a better way. Does anyone know a more elegant way?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…