Hi,
rownames(a)
# [1] "4"   "5"   "6"   "7"   "8"   "9"   "11"  "12"  "13"  "15"  "16"  "17" 
#[13] "18"  "21"  "40"  "48"  "50"  "52"  "53"  "54"  "81"  "101" "102" "103"
#[25] "108" "118" "147" "803" "805" "806" "807" "808" "809" "810" "812" "814"
#[37] "815" "816" "822" "825"
 rownames(a1)
 #[1] "4"   "5"   "6"   "7"   "8"   "9"   "11"  "12"  "13"  "15"  "16"  "17" 
#[13] "18"  "21"  "40"  "48"  "50"  "52"  "53"  "54"  "81"  "101" "102" "103"
#[25] "108" "118" "147" "803" "805" "806" "807" "808" "809" "810" "812" "814"
#[37] "815" "816" "822" "825"


  names(a1)
#[1] "efficiency"


----- Original Message -----
From: jpm miao <miao...@gmail.com>
To: r-help <r-help@r-project.org>
Cc: 
Sent: Monday, May 6, 2013 4:03 AM
Subject: [R] How can I access the rowname of a data?

Hi,

   Below is the output from an R package. The first column (4, 5, 6, 7,
which is unnamed) is the company name (code), while the second column
efficiency is the performance of each company, which is the primary output
result. How can I access the first column,  rowname, 4, 5, 6, 7, 8, 9, 11?
How can I build a dataframe consisting of two columns, the company name
(code) and the efficiency?
   as.data.frame(a)   produce only a column with company names, where
company names are not accessible.

   Thanks,

Miao


> a
    efficiency
4   0.26902196
5   0.30967213
6   0.33841116
7   0.36174368
8   0.36415004
9   0.37977151
11  0.42136627
12  0.40270465
13  0.49386586
15  0.12549416
16  0.17616129
17  0.45815803
18  0.09380655
21  0.97223375
40  0.43234228
48  0.25185516
50  0.28382549
52  0.44653074
53  0.27899931
54  0.42288119
81  0.49108330
101 0.20489971
102 0.24817017
103 0.36290391
108 0.23457172
118 0.25237865
147 0.25926483
803 0.45134936
805 0.36135729
806 0.28311573
807 0.32053914
808 0.35295777
809 0.17983115
810 0.30132804
812 0.48614262
814 0.30770005
815 0.29402445
816 0.35863589
822 0.50282266
825 0.46845802
> dput(a)
structure(c(0.269021958172058, 0.30967212679043, 0.338411157000573,
0.361743675159821, 0.364150044117951, 0.37977150519361, 0.421366274731659,
0.402704652137264, 0.49386585901599, 0.125494157670888, 0.176161288740361,
0.458158033521881, 0.0938065485975032, 0.972233754473899,
0.432342283512805,
0.251855164210068, 0.283825485987841, 0.446530739128589, 0.278999313704237,
0.422881194129863, 0.491083297407732, 0.20489970948236, 0.248170174737282,
0.362903909816553, 0.234571723781862, 0.252378650048782, 0.259264826952972,
0.451349355848852, 0.361357286628178, 0.283115732632982, 0.32053914247248,
0.352957770657268, 0.179831147819322, 0.30132803776434, 0.486142623827358,
0.307700045108983, 0.29402444509927, 0.358635886286322, 0.502822662489642,
0.468458021786023), .Dim = c(40L, 1L), .Dimnames = list(c("4",
"5", "6", "7", "8", "9", "11", "12", "13", "15", "16", "17",
"18", "21", "40", "48", "50", "52", "53", "54", "81", "101",
"102", "103", "108", "118", "147", "803", "805", "806", "807",
"808", "809", "810", "812", "814", "815", "816", "822", "825"
), "efficiency"))


> a1<-as.data.frame(a)
> View(`a1`)
> a1$name
NULL
> a1$names
NULL
> a1$row.names
NULL
> a1$efficiency
[1] 0.26902196 0.30967213 0.33841116 0.36174368
[5] 0.36415004 0.37977151 0.42136627 0.40270465
[9] 0.49386586 0.12549416 0.17616129 0.45815803
[13] 0.09380655 0.97223375 0.43234228 0.25185516
[17] 0.28382549 0.44653074 0.27899931 0.42288119
[21] 0.49108330 0.20489971 0.24817017 0.36290391
[25] 0.23457172 0.25237865 0.25926483 0.45134936
[29] 0.36135729 0.28311573 0.32053914 0.35295777
[33] 0.17983115 0.30132804 0.48614262 0.30770005
[37] 0.29402445 0.35863589 0.50282266 0.46845802
> a1
    efficiency
4   0.26902196
5   0.30967213
6   0.33841116
7   0.36174368
8   0.36415004
9   0.37977151
11  0.42136627
12  0.40270465
13  0.49386586
15  0.12549416
16  0.17616129
17  0.45815803
18  0.09380655
21  0.97223375
40  0.43234228
48  0.25185516
50  0.28382549
52  0.44653074
53  0.27899931
54  0.42288119
81  0.49108330
101 0.20489971
102 0.24817017
103 0.36290391
108 0.23457172
118 0.25237865
147 0.25926483
803 0.45134936
805 0.36135729
806 0.28311573
807 0.32053914
808 0.35295777
809 0.17983115
810 0.30132804
812 0.48614262
814 0.30770005
815 0.29402445
816 0.35863589
822 0.50282266
825 0.46845802
> View(`a1`)
> a1[1,]
[1] 0.269022
> a1[2,]
[1] 0.3096721

    [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to