如何在R中创建整数向量列表
基本问题:在R中,如何创建一个列表,然后用向量元素填充它如何在R中创建整数向量列表,r,R,基本问题:在R中,如何创建一个列表,然后用向量元素填充它 l <- list() l[1] <- c(1,2,3) l使用中的[[1]] l[[1]] <- c(1,2,3) l[[2]] <- 1:4 l[[1]]根据?“[”(在“递归(类似列表的)对象”一节下): 基本上,对于列表,[选择多个元素,因此替换必须是列表(而不是示例中的向量)。下面是如何在列表上使用[的示例: l <- list(c(1,2,3), c(4,5,6)) l[1] <-
l <- list()
l[1] <- c(1,2,3)
l使用中的[[1]]
l[[1]] <- c(1,2,3)
l[[2]] <- 1:4
l[[1]]根据?“[”
(在“递归(类似列表的)对象”一节下):
基本上,对于列表,[
选择多个元素,因此替换必须是列表(而不是示例中的向量)。下面是如何在列表上使用[
的示例:
l <- list(c(1,2,3), c(4,5,6))
l[1] <- list(1:2)
l[1:2] <- list(1:3,4:5)
l <- vector(mode="list", length=N)
Indexing by ‘[’ is similar to atomic vectors and selects a list of
the specified element(s).
Both ‘[[’ and ‘$’ select a single element of the list. The main
difference is that ‘$’ does not allow computed indices, whereas
‘[[’ does. ‘x$name’ is equivalent to ‘x[["name", exact =
FALSE]]’. Also, the partial matching behavior of ‘[[’ can be
controlled using the ‘exact’ argument.
l <- list(c(1,2,3), c(4,5,6))
l[1] <- list(1:2)
l[1:2] <- list(1:3,4:5)
l[[1]] <- 1:3