是否可以按行而不是按列对数据集的值进行舍入而不是旋转?标准方法是使用mutate_at
or now with对列进行舍入,across
但我更愿意按特定行进行:
library(tidyverse)
set.seed(10)
df <- data.frame(let = sample(letters, 20),
x = rnorm(20),
y = rnorm(20) + 10,
z = rnorm(20) + 30)
df
#for rows where "let" = i, j, k, h round to 2 decimal places using ~round(., 2)
round_2 = c("i", "j", "k", "h")
#for rows where "let" = a, b, c, d, e round to decimal places using ~round(., 0)
round_0 = c("a", "b", "c", "d")
#typical type approach with columns
#df %>%
# mutate(across(matches("x|y"), ~round(., 0)))
#df %>%
# mutate(across(matches("z"), ~round(., 2)))
也许rowwise
可以在这里使用?
谢谢