?USPersonalExpenditure USPersonalExpenditure rownames(USPersonalExpenditure) colnames(USPersonalExpenditure) dim(USPersonalExpenditure) USPersonalExpenditure[1,3] USPersonalExpenditure["Food and Tobacco", "1950"] USPersonalExpenditure[1, "1950"] USPersonalExpenditure[1, c(5, 3, 1)] USPersonalExpenditure["Food and Tobacco", c("1960", "1950", "1940")] USPersonalExpenditure[1, ] USPersonalExpenditure["Food and Tobacco", ] USPersonalExpenditure["Food and Tobacco", , drop = FALSE] USPersonalExpenditure[, c("1940", "1950")] USPersonalExpenditure[1:3, c("1940", "1950")] sum(USPersonalExpenditure[, "1940"]) USPersonalExpenditure[1] USPersonalExpenditure[2] USPersonalExpenditure[7] length(USPersonalExpenditure) sum(USPersonalExpenditure) game1 <- matrix(c("X", "", "O", "", "X", "O", "", "", ""), ncol = 3) game2 <- matrix(c("X", "", "O", "", "X", "O", "", "", ""), ncol = 3, byrow = TRUE) game1[3, 3] <- "X" new_game <- matrix(data = "", ncol = 3, nrow = 3) pieces <- c("rook", "knight", "bishop", "queen", "king", "bishop", "knight", "rook") pawns <- rep("pawn", 8) board <- rbind(rev(pieces), pawns, matrix("", nrow = 4, ncol = 8), pawns, pieces) rownames(board) <- 8:1 colnames(board) <- letters[1:8] USPersonalExpenditure["Personal Care", "1955"] <- "Unknown" USPersonalExpenditure rm(USPersonalExpenditure) (edu_spend <- unname(USPersonalExpenditure["Private Education", ])) (edu_yr <- seq(from = 0, to = 20, by = 5)) plot(edu_yr, edu_spend) my_model <- lm(edu_spend ~ edu_yr) my_model summary(my_model) abline(my_model) plot(my_model) str(my_model) ad_mouse_colony <- list("9.1", FALSE) ad_mouse_colony <- list(room = "9.1", bsl3 = FALSE) ad_mouse_colony$conditions <- list(bedding = "straw", light_hrs = 12) ad_mouse_colony$count <- c(male = 10, female = 0) ad_mouse_colony[["variants"]] <- c("APP695swe", "PS1-dE9") ad_mouse_colony[[1]] ad_mouse_colony[["room"]] ad_mouse_colony$room names(ad_mouse_colony) ad_mouse_colony[c(1,4)] ad_mouse_colony $bsl3 <- NULL x <- c(0, 1, 1, 2, 3, 5, 8, 13, 21) attr(x, "description") <- "Fibonacci series" attr(x, "description") attributes(x) str(attributes(x)) state_db <- data.frame(state.name, state.abb, state.area, state.center, stringsAsFactors = FALSE) state_db summary(state_db) head(state_db) state_db$state.abb state_db[[ "state.abb" ]] state_db[[ 2 ]] state_db[, 2] state_db[ , 1:2] state_db[41:50, 1:2] state_db[c(50, 1), c("state.abb", "x", "y")] state_db[order(state_db$state.area)[1:5], ] state_db[order(state_db$state.area), ][1:5, ] rownames(state_db) <- state.abb state_db[c("NY", "NJ", "CT", "RI"), c("x", "y")] names(state_db) <- c("name", "abb", "area", "long", "lat") state_db$division <- state.division state_db$z.size <- (state_db$area - mean(state_db$area))/sd(state_db$area) state_db[ , "z.size", drop = FALSE] state_db[state_db$area < median(state_db$area), "name"] state_db[state_db$area < median(state_db$area), "name", drop = FALSE] coastal <- state_db[ state_db$division %in% c("New England", "Middle Atlantic", "South Atlantic", "Pacific"), ] subset(state_db, area < median(area), select = name) coastal <- subset(state_db, division %in% c("New England", "Middle Atlantic", "South Atlantic", "Pacific") ) subset(state_db, select = c(name, abb)) subset(state_db, select = -c(long, lat)) plot(area ~ division, data = state_db) plot(log(area) ~ division, data = state_db) plot(lat ~ long, data = state_db) text(lat ~ long, data = state_db, rownames(state_db)) ablation <- read.csv("Ablation.csv", header = TRUE, stringsAsFactors = TRUE) names(ablation)[names(ablation) == "SCORE"] <- "Score" write.table(ablation, file = "ablation.txt", quote = FALSE, col.names = NA, sep = "\t") write.table(ablation, file = "ablation.txt", quote = FALSE, row.names = FALSE, sep = "\t") mySummary <- function(x) { my_mean <- mean(x) my_sd <- sd(x) list(mean = my_mean, sd = my_sd) } mySummary(rnorm(100)) raiseNumber <- function(x, power = 1) { x ^ power } raiseNumber(10) raiseNumber(10, 3) num_iterations <- 100 my_means <- numeric(length = num_iterations) for (i in 1:num_iterations) { x <- rnorm(10000) my_means[i] <- mean(x) } hist(my_means)