want to remove an object from a sub list

Viewed 39

please I want to remove just 20 from score.

list1 <- list(numbers=c(1,2),logical=TRUE, strings=c("a","b","c"),score=c(15,20,30))
rm(list=list1[[4]][[2]])

Warning message:
In rm(list = list1[[4]][[2]]) : object '20' not found

list1[[4]][2]
#[1] 20
list1[[4]][2] <- NULL

Error in list1[[4]][2] <- NULL : replacement has length zero

1 Answers
list1 <- list(numbers=c(1,2),logical=TRUE, strings=c("a","b","c"),score=c(15,20,30))

Remove 20:

correctedscore <- list1$score[-(2:2)]

Recreate your list:

list1 <- list(numbers=c(1,2),logical=TRUE, strings=c("a","b","c"),correctedscore)
Related