
String template
# string template
my_name <- "Toy"
age <- 34
city <- "Bangkok"
text <- glue("Hello my name is {my_name} and I'm {age} years old and I live in {city}")
## คล้ายกับ Paste เเต่ glueทำได้ง่ายกว่า
Working with date
# working with date
d <- "2023-06-17"
class(d)
**library(lubridate)**
ymd(d) ## เท่านี้ก็จะเปลี่ยนจาก text เป็น date






Dplyr

Select
View(mtcars)
select(mtcars, mpg, cyl, disp, hp, am)
select(mtcars, mile_per_gallon = mpg, weight = wt)
select(mtcars, starts_with("a"))
select(mtcars, ends_with("p"))
select(mtcars, contains("a"))
Row_names to column
## rownames to column การเปลี่ยน row_name ให้เป็นcolumn พร้อมเปลี่ยนชื่อ
mtcars <- rownames_to_column(mtcars, var="model")

Filter by condition
## filter by condition
## filter mtcars dataframe for hp>100
## & = and , | = or
filter(mtcars, hp > 100 | disp > 300 | mpg > 15)
filter(mtcars, model == "Mazda RX4")
filter(mtcars, grepl("^M", model))