2012-04-17 34 views
3

快速問題。我的列表(R)的樣子:R,從鍵值中獲取密鑰(散列)

> mylist 
$width 
[1] 32 

隨着MYLIST [1]我得到:

$width 
[1] 32 

但我怎麼得到:

$width 

感謝和歡呼聲。

+0

可能重複(http://stackoverflow.com/questions/3737194/dictionary-data-structure-in-r) – 2012-04-17 20:25:55

回答

8

元素的名稱存儲在屬性中,名爲「names」,可通過names函數訪問。

嘗試這種情況:

mylist <- list(width=42, height=13) 
names(mylist) # "width" "height" 
names(mylist)[1] # "width" 

mylist[["width"]] # 42 

mylist[sort(names(mylist))] # sort mylist by the names... 
[R中的詞典數據的結構]的