You could use apply() to do this:
library(dplyr)
df <- data_frame(
temp = c(21, 22, 22, 24, 25, 25, 26, 27),
prec = c(222.34, 550, 550, 659.43, 700, 700, 750.500, 790),
alt = c(400, 400, 550, 650, 700, 750, 750, 800)
)
apply(df, 2, unique)
#> temp prec alt
#> [1,] 21 222.34 400
#> [2,] 22 550.00 550
#> [3,] 24 659.43 650
#> [4,] 25 700.00 700
#> [5,] 26 750.50 750
#> [6,] 27 790.00 800
The above generated a matrix because there are 6 unique values in each column. This may not always be the case. I modified the example a bit to show what happens when this isn't the case. Here, you get a list instead of a matrix because the variables are not all the same length.
df <- data_frame(
temp = c(21, 22, 22, 24, 25, 25, 26, 27),
prec = c(222.34, 550, 550, 659.43, 700, 700, 750.500, 790),
alt = c(400, 400, 400, 650, 700, 750, 750, 800)
)
apply(df, 2, unique)
#> $temp
#> [1] 21 22 24 25 26 27
#>
#> $prec
#> [1] 222.34 550.00 659.43 700.00 750.50 790.00
#>
#> $alt
#> [1] 400 650 700 750 800
Created on 2022-05-17 by the reprex package (v2.0.1)