R(week 12)
set.seed(125) myMat <- matrix(rpois(20, 3), nrow = 4) myMat dim(myMat) apply(myMat, 2, max) apply(myMat, 1, min) apply(myMat, 2, range) airquality split(airquality$wind, airquality$Month) %>% split(airquality[]) lapply(1:5, rnorm) lapply(1:4, rnorm, mean = 10) lapply(1:5, rnorm, n = 5) #split(airquality$Temp, airquality$Month) %>% # lapply(mean, na.rm = ) list1 <- list(A = matrix(1:16, 4), B = matrix(1:16, 2), C=1:5) list2 <- list(A = matrix(1:16, 4), B=matrix(1:16, 8), C=15:1) list1 mapply(identical,list1, list2) ?mapply #chengji tongji library(tidyverse) getNum <- function(n){ myName <- sample(letters, n, replace = TRUE) %>% paste0(collapse = "") %>% str_to_title() return (myName) } getNum(4) stNames <- c() for(i in 1:50){ gName <- getNum(sample(2:8, 1)) fName <- getNum(sample(2:3, 1)) stNames[i] <- paste(gName, fName) } stNames English <- sample(30:100, 50, replace = TRUE) Management <- sample(70:89, 50, replace = TRUE) Rdatascience <- sample(60:100, 50, replace = TRUE) roster <- data.frame(stNames, English, Management, Rdatascience) dim(roster) view(roster) ave_score <- roster[ ,-1] %>% apply(1, mean) roster1 <- cbind(roster, ave_score) view(roster1)