# Named vectors v <- LETTERS[1:10] names(v) <- letters[1:10] v[2] v["b"] v[c("b","a","d")] v[7:11] <- c("a","p","p","l","e") names(v)[11] <- "last" # Matrices m <- matrix(1:6, nrow = 2) attributes(m) # list all the meta-data fields for m attr(m, "dim") # get the value of specific meta-data field(s) # Lists l <- attributes(m) class(l) l$dim # accessing contents of list component x <- rnorm(10) y <- rnorm(10) z <- t.test(x,y) str(z) attributes(z) z$statistic # access the value of the statistic component z[[1]] # as above; access the value of the statistic component z[1] # returns a list, with just the first component z[1:3] # returns a list, with the first three components # Simulate the unethical practice of adding measurements until you get the result you want set.seed(2) n <- 3 x <- rnorm(n) y <- rnorm(n) pval <- c(NA, NA, t.test(x, y)$p.value) while (pval[n] > 0.05) { x[n + 1] <- rnorm(1) y[n + 1] <- rnorm(1) test <- t.test(x, y) pval[n + 1] <- test$p.value n <- n + 1 } plot(1:n, pval)