Strings
str_single <- "Hello"
str_multiline <- "Multiline\nstring"
toupper(str_multiline)
Useful string manipulation with stringr
:
library(stringr)
name <- "John Doe"
str_to_lower(name) # "john doe"
str_split(name, " ") # List of "John" and "Doe"
Numbers
integer <- 42L
floating_point <- 3.14
complex_number <- complex(real = 2, imaginary = 3)
# Converting between types
float_to_int <- as.integer(3.7) # 3
Working with vectors:
nums <- c(1, 2, 3, 4, 5)
mean(nums) # 3
sum(nums) # 15