Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 88

Warning – Silent failing of unlist()

Оглавление

Lists are more complex than vectors, instead of failing with a warning and requiring additional options to be set, the unlist() function will silentlymake some decisions for you.

# A list of vectors of integers: L <- list(1L,c(-10L:-8L)) unlist(L) ## [1] 1 -10 -9 -8 # Note the named real-valued extra element: L <- list(c(1:2),c(-10:-8), “pi_value” = pi) unlist(L) ## ## 1.000000 2.000000 -10.000000 -9.000000 -8.000000 ## pi_value ## 3.141593

Apart from performance considerations, it might also be necessary to convert parts of a list to a vector, because some functions will expect vectors and will not work on lists.

The Big R-Book

Подняться наверх