I can define a list containing NULL elements: > myList <- list("aaa",NULL,TRUE) > names(myList) <- c("first","second","third") > myList $first [1] "aaa" $second NULL $third [1] TRUE > length(myList) [1] 3
However, if I assign NULL to any of the list element then such element is deleted from the list: > myList$second <- NULL > myList $first [1] "aaa" $third [1] TRUE > length(myList) [1] 2 > # > myList$first <- NULL > myList $third [1] TRUE > length(myList) [1] 1 Instead vectors cannot include NULL element: > vec <- c(TRUE,NULL,FALSE) > vec [1] TRUE FALSE > length(vec) [1] 2 > vec[1] <- NULL Error in vec[1] <- NULL : replacement has length zero Is the above shown behaviour of list data structures to be expected ? I took me a lot of sweat to figure out this wierd behaviour was the cause of a bug in my big program. In general, if I have a list with some elements initialized to NULL, that can be changed dynamically, then how can I reinitialize such elements to NULL without deleting them from the list ? Thank you in advance, Maura [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.