我有一台4x4的Tibble,我正在用它练习各种dplyr功能.
我想计算每一行的范围,并在新列中将该行的范围显示为单个数字.
以下是我的代码:
my_tibble <- data.frame(col1 = c(1:5), col2 = c(6:10), col3 = c(11:15), col4 = c(16:20))
my_tibble <- as_tibble(my_tibble)
我try 了一个for循环来解决这个问题,但无法理解for循环如何与子集的Tibble数据交互:
for (rows in 1:4)
my_range <- max(my_tibble[rows, 1:4]) - min(my_tibble[rows, 1:4])
总而言之,我想要尽可能多的方式在Tibble的新列中显示max-min(即范围).