Learn Programming in R – Introduction
https://campus.datacamp.com/courses/free-introduction-to-r/chapter-2-vectors-2?ex=2
1. Check Type: class()
2. Array: c()
3. SetName: name(_variables) = c(1,2,3,4, …)
4. Can do Array1 + Array2
5. Sum of all array items: sum()
6. Array index access 3rd item: Array_variable[3]
7*. poker_midweek <- poker_vector[c(2,3,4)]
8.
9. matrix(1:9, byrow = TRUE, nrow = 3)
10. # Name the columns / rows:
colnames(star_wars_matrix) = region
rownames(star_wars_matrix) = titles
11. Sum of matrix by row:worldwide_vector <- rowSums(star_wars_matrix)
12. column bind: #Bind the new variable worldwide_vector as a column to star_wars_matrix
all_wars_matrix <- cbind(star_wars_matrix, worldwide_vector)
13. row bind: rbind(star_wars_matrix, star_wars_matrix2)
14. select all data of a column: non_us_all <- all_wars_matrix[,2]
15. Distinct: factor()
16. factor_temperature_vector <- factor(temperature_vector, order = TRUE, levels = c(“Low”, “Medium”, “High”))
17. :head() tail()
18. planets_df <- data.frame(name, type, diameter, rotation, rings)
cbind(name, type, diameter, rotation, rings)
19. # Check the structure of planets_df
str(planets_df)
20. subset(planets_df, subset = diameter < 1)
21.
# Use order() to create positions
positions <- order(planets_df$diameter)
# Use positions to sort planets_df
planets_df[positions, ]
22.
- Vectors (one dimensional array): can hold numeric, character or logical values. The elements in a vector all have the same data type.
- Matrices (two dimensional array): can hold numeric, character or logical values. The elements in a matrix all have the same data type.
- Data frames (two-dimensional objects): can hold numeric, character or logical values. Within a column all elements have the same data type, but different columns can be of different data type.
23. assign column name into a list: shining_list <- list(fieldName1 = mov, fieldName2 = act, fieldName3 = rev)
最新評論