Name columns after using an aggregate function

I used the aggregate function to get the range by power level. I am trying to rename columns, but exiting the aggregate function does not have min and max as separate columns.

# example data
size_cor <- data.frame(SpCode=rep(c(200,400,401),3),Length=(c(45,23,56,89,52,85,56,45,78)))


# aggregate function
spcode_range <- with(size_cor, aggregate(Length, list(SpCode), FUN = range))

Conclusion:

spcode_range 

  Group.1 x.1 x.2
1     200  45  89
2     400  23  52
3     401  56  85

Data structure:

str(spcode_range)

'data.frame':   3 obs. of  2 variables:
 $ Group.1: num  200 400 401
 $ x      : num [1:3, 1:2] 45 23 56 89 52 85

dim(spcode_range)
[1] 3 2

The output consists of three columns: Group.1, x.1(min) and x.2(max), but in the data frame is only 2 columns. I tried setNames to rename and name without success, because I try to name three columns when R has only 2 columns.

+4
source share

Source: https://habr.com/ru/post/1599335/


All Articles