How to get the first row of the first column in transformed data frame

I transformed a data frame but I can't find a way to extract the row name of the first row (In my example it's "color"):

df <- read.table(text = " color birds    wolfs     
                  red           9         7 
                 red           8         4 
                 red           2         8 
                 red           2         3 
                 black         8         3 
                 black         1         2 
                 black         7         16 
                 black         1         5 
                 black         17        7 
                 black         8         7 
                 black         2         7 
                 green         20        3 
                 green         6         3 
                 green         1         1 
                 green         3         11 
                 green         30         1  ",header = TRUE)
df_t<-t(df)
[,1]  [,2]  [,3]  [,4]  [,5]    [,6]    [,7]    [,8]    [,9]    [,10]   [,11]   [,12]   [,13]   [,14]   [,15]   [,16]  
color "red" "red" "red" "red" "black" "black" "black" "black" "black" "black" "black" "green" "green" "green" "green" "green"
birds " 9"  " 8"  " 2"  " 2"  " 8"    " 1"    " 7"    " 1"    "17"    " 8"    " 2"    "20"    " 6"    " 1"    " 3"    "30"   
wolfs " 7"  " 4"  " 8"  " 3"  " 3"    " 2"    "16"    " 5"    " 7"    " 7"    " 7"    " 3"    " 3"    " 1"    "11"    " 1" 

If I use: df_t[1,1] I get:

color 
"red"

How can I extract only the string "color" and save it.

Answers


In your example "color" is one of the row names. Try rownames(df_t)[1]


We can use names

str1 <- names(df_t[1,1])
str1
#[1] "color"

Need Your Help