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: l
ist(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
📌 view of table
Viewhead: preview 6glimpseas_tibble(tablename)str: get structurecolnames: get column names
✅ here, skimr, Packages
- here: bring file
- skimr: summarize data
- janitor: clean data
📌 fumctions in R
arrange:penguins %>% arrange(-bill_length_mm)group by:penguins %>% group_by(island)drop_na()summarize:filter:penguins %>% filter(island == "Torgersen")
1
> penguins %>% group_by(island) %>% drop_na() %>% summarize(mean_bill_length_mm= mean(bill_length_mm))
mutate
1
2
3
> example_df <- bookings_df %>%
+ mutate(number_canceled = sum(is_canceled))
> head(example_df)
✅ check for bias
Simdesignpackage- bias(check1, check2)
- 👍🏻 close to 0
📌
This post is licensed under CC BY 4.0 by the author.