I have a 4x4 tibble, and I'm practicing various dplyr functions on it.
I would like to calculate the range of each row, and display the range of that row as a single number in a new column.
Here is my code:
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)
I attempted a for loop to solve this problem but can't understand how the for loop interacts with the subsetted tibble data:
for (rows in 1:4)
my_range <- max(my_tibble[rows, 1:4]) - min(my_tibble[rows, 1:4])
In summary, I would like as many ways possible to display the max-min (i.e. range) in a new column in the tibble.