mutate function r code example

Example 1: r how to mutate

mutate(.data, ...)

# S3 method for data.frame
mutate(
  .data,
  ...,
  .keep = c("all", "used", "unused", "none"),
  .before = NULL,
  .after = NULL
)

Example 2: r mutate function

# Create the 'month' column
df %>%
  mutate(month = str_sub(birthday,1,2))
 
# Create the 'day' column
df %>%
  mutate(day = str_sub(birthday,3,4))
 
# Create the 'year' column
df %>%
  mutate(year = str_sub(birthday,5))

Example 3: r code mutate

mutate(.data, ...)

# S3 method for data.frame
mutate(
  .data,
  ...,
  .keep = c("all", "used", "unused", "none"),
  .before = NULL,
  .after = NULL
)

transmute(.data, ...)

Example 4: r mutate function

#remove %
students <- students %>% 
  mutate(score=gsub('\\%','',score))

Tags:

C Example