### Name: Extract ### Title: Extract or Replace Parts of an Object ### Aliases: Extract Subscript [ [.listof [.simple.list [[ $ [<- [[<- $<- ### Keywords: array list ### ** Examples x <- 1:12; m <- matrix(1:6, nrow=2); li <- list(pi=pi, e = exp(1)) x[10] # the tenth element of x x <- x[-1] # delete the 1st element of x m[1,] # the first row of matrix m m[1, , drop = FALSE] # is a 1-row matrix m[,c(TRUE,FALSE,TRUE)]# logical indexing m[cbind(c(1,2,1),3:1)]# matrix index m <- m[,-1] # delete the first column of m li[[1]] # the first element of list li y <- list(1,2,a=4,5) y[c(3,4)] # a list containing elements 3 and 4 of y y$a # the element of y named a ## non-integer indices are truncated: (i <- 3.999999999) # "4" is printed (1:5)[i] # 3 ## recursive indexing into lists z <- list( a=list( b=9, c='hello'), d=1:5) unlist(z) z[[c(1, 2)]] z[[c(1, 2, 1)]] # both "hello" z[[c("a", "b")]] <- "new" unlist(z) ## check $ and [[ for environments e1 <- new.env() e1$a <- 10 e1[["a"]] e1[["b"]] <- 20 e1$b ls(e1)