相同點(diǎn):
兩者作用都是“提取”躲履,當(dāng)從一個(gè)向量或矩陣中提取第3個(gè)元素時(shí)炼幔,兩者結(jié)果相同!
> aaa<-c(1,2,3,4,5)
> aaa[3]
[1] 3
> aaa[[3]]
[1] 3
不同點(diǎn):
當(dāng)數(shù)據(jù)不是一個(gè)list時(shí)滚局,情況就不同了居暖。
[] extracts a list, [[]] extracts elements within the list
The [[ form allows only a single element to be selected using integer or character indices, whereas [ allows indexing by vectors.
令一個(gè)區(qū)別是 [[ 可通過(guò)參數(shù)“exact”激活模糊匹配,[]則不行藤肢。
> alist <- list(c("a", "b", "c"), c(1,2,3,4), c(8e6, 5.2e9, -9.3e7))
> alist[[1]]
[1] "a" "b" "c"
> alist[1]
[[1]]
[1] "a" "b" "c"
看起來(lái)結(jié)果一樣太闺,但其實(shí)數(shù)據(jù)類(lèi)型不一樣的:
> str(alist[[1]])
chr [1:3] "a" "b" "c"
> str(alist[1])
List of 1
$ : chr [1:3] "a" "b" "c"
參考文獻(xiàn)1:https://blog.csdn.net/yiifaa/article/details/73252980
參考文獻(xiàn)2:https://ask.csdn.net/questions/707505: