2017-10-16 51 views
0

這似乎是一個初學者問題,但我無法在任何地方找到答案。我知道如何從列表中使用LISTNAME [[1]]中提取元素,但輸出將始終包括指數像R:提取列表元素但輸出中沒有索引號

[1] First element of the list 

同樣是使用類似名稱LISTNAME $名稱或不公開(LISTNAME $名字真)。我想要的是

First element of the list 

我當然可以使用正則表達式刪除索引號,但我懷疑這是它應該是這樣:-)

回答

1

[1]出現的原因是因爲所有的原子類型在R中是向量(類型爲字符,數字等),即在你的情況下是長度爲1的向量。

如果你想看到的輸出,而不[1]的simples方式是cat對象:

> listname <- list("This is the first list element", 
        "This is the second list element") 
> cat(listname[[1]], "\n") 
This is the first list element 
> 
+0

這工作,謝謝! – Ryan

+0

然後驗證答案;) –