Search code examples
rvectornamed

How to get the name of a named num in R?


I am trying to access the name of a named num in R. My list looks like this:

correlationCoeffs

Line          H.points.per.game  V.points.per.game  H.fg.made.per.game  V.fg.made.per.game
0.3724764838  0.2315726001       0.2315726001       0.2156721183        0.2156721183 

I know how to access specific numbers and specific entries as so:

correlationCoeffs[["Line"]]
    0.3724764838
correlationCoeffs["Line"]
    Line
    0.3724764838

But I am looking to access the actual name for a given index (for example, given index 1, I want to get "Line" as the result).


Solution

  • Using names() and supplying the index can help with that.

    names(correlationCoeffs[index])