Post

R_basic commands

✅ Vector and List and date

  • Vector: type of data
    • logical(boolean)
    • integer
    • double
    • character
1
2
3
4
5
x <- c(1, 3, 5)
names(x) <- c("a", "b", "c")
x
x[2] #3
x["b"] #3
  • List: list(x, y, z)

  • Date: ymd("2023-01-20")

1
2
ymd_hms("2021-01-20 20:11:59")
# [1] "2021-01-20 20:11:59 UTC"

✅ Frame, Matrices

  • Frame, data.frame
1
2
3
4
5
6
7
data.frame(x = c(1, 2, 3) , y = c(1.5, 5.5, 7.5))

#result
#   x   y
# 1 1 1.5
# 2 2 5.5
# 3 3 7.5
  • Matrices
1
2
3
4
5
matrix(c(3:8), nrow = 2)

#      [,1] [,2] [,3]
# [1,]    3    5    7
# [2,]    4    6    8

✅ Pipe

  • A tool in R for expressing a sequence of multiple operations, represented with %>%

✅ Packages of tidyverse

  • ggplot2: visualize
  • tidyr: clean data
  • readr: read data
  • dplyr: data manipulation

This post is licensed under CC BY 4.0 by the author.