本章主要是讲关于R包的结构,向量。很多书都是从这开始讲,所以这一章是最蒙但学的最多的。这是从一个方面讲述了这本书的好的地方。

向量的包含关系如上图所示!
使用typeof函数可以快速确定向量的类型,length函数可以确认向量的长度。
数值型向量中双精度及整数型需要进行区别:
- 双精度为近似值 所以判断是要用near函数
-
特殊数值的关系及存在
特殊数值
具体可以参照这篇博客 https://baijiahao.baidu.com/sid=1577252276224639706&wfr=spider&for=pc

向量取子集
[]表示向量取子集
x <- c("one", "two", "three", "four", "five")
x[c(3, 2, 5)]#注意是位置哦
#> [1] "three" "two" "five"
20.5.3 Lists of condiments 这实在是太形象了 不忍删去
The difference between [
and [[
is very important, but it’s easy to get confused. To help you remember, let me show you an unusual pepper shaker.

If this pepper shaker is your list x
, then, x[1]
is a pepper shaker containing a single pepper packet:

x[2]
would look the same, but would contain the second packet. x[1:2]
would be a pepper shaker containing two pepper packets.
x[[1]]
is:

If you wanted to get the content of the pepper package, you’d need x[[1]][[1]]
:

网友评论