Rename Columns rh0, rh1, rh2... rh100

Hi everyone,
I am trying to rename columns from a matrix such that they represent variables from the data source.
For more context, I have NASA GEDI data in hdf5 format. I've extracted the relative height (rh) metrics but they output to a matrix with the column names V1, V2, V3... V101.

What I want is for the column names to match the rh height metrics as follows: rh0, rh1, rh2...rh100.

Thank you for any suggestions
Sincerely,
Schyler

You can build the column names with the paste0() function.

MAT <- matrix(1:20, ncol = 10)
MAT
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    3    5    7    9   11   13   15   17    19
[2,]    2    4    6    8   10   12   14   16   18    20
colnames(MAT) <- paste0("rh", 0:9)
MAT
     rh0 rh1 rh2 rh3 rh4 rh5 rh6 rh7 rh8 rh9
[1,]   1   3   5   7   9  11  13  15  17  19
[2,]   2   4   6   8  10  12  14  16  18  20
1 Like

Thank you so much FJCC, I appreciate your help

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.