相同点:
两者作用都是“提取”,当从一个向量或矩阵中提取第3个元素时,两者结果相同!
> aaa<-c(1,2,3,4,5)
> aaa[3]
[1] 3
> aaa[[3]]
[1] 3
不同点:
当数据不是一个list时,情况就不同了。
[] 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.
令一个区别是 [[ 可通过参数“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"
看起来结果一样,但其实数据类型不一样的:
> str(alist[[1]])
chr [1:3] "a" "b" "c"
> str(alist[1])
List of 1
$ : chr [1:3] "a" "b" "c"
参考文献1:https://blog.csdn.net/yiifaa/article/details/73252980
参考文献2:https://ask.csdn.net/questions/707505: