names above the numbers of a numerical vector in R. how to change them?

Viewed 20

in R there were several times on which a numerical vector had names before each numeric value as this:

class(oral_NO_AR_comp$clustering$clust1)

output: 1 "numeric"

and the content looks like this:

enter image description here

THe point here is that I need to change the names of the strings above the numbers, is there a way to do that?r

1 Answers

You can get those names with

names(oral_NO_AR_comp$clustering$clust1).

You can use

names(oral_NO_AR_comp$clustering$clust1)<- <whatever you want> 
# or
setNames(oral_NO_AR_comp$clustering$clust1, <whatever you want)

to change the names if you like. You can also use remove the names with

unname(oral_NO_AR_comp$clustering$clust1)

Note that these functions (with the exception of names<-) do not change the original value, they return a new value. If you want to replace the original value, be sure to assign it <- to the original variable.

Related