R语言数据操作(Data Manipulation with R)(Chapter 1.3 - 1.6 )
> ##### 1.3 模式与类的检测
> is.array()
> is.numeric()
> is.na()
> is.factor()
> is.list()
> is.data.frame()
......
> ##### 1.4 R对象的结构
> mylist <- list(a = c(1,2,3), b = c("cat", "dog", "duck"), d= factor("a", "b", "a"))
> #list()函数返回一个对象的长度和Dim
> ls.str(mylist)
a : num [1:3] 1 2 3
b : chr [1:3] "cat" "dog" "duck"
d : Factor w/ 1 level "a": NA
> #summary()函数提供列表元素的名称,长度,类别以及模式,但都是最高级别的元素
> summary(mylist)
Length Class Mode
a 3 -none- numeric
b 3 -none- character
d 1 factor numeric
> nestlist <- list(a = list(matrix(rnorm(10),5,2), val = 3),
+ b = list(sample(letters, 10), values = runif (5)),
+ c = list(list(1:10, 1:20), list(1:5, 1:10)))
> summary(nestlist)
Length Class Mode
a 2 -none- list
b 2 -none- list
c 2 -none- list
> #str()提供对象中所有组件的性质细节,vec.len=参数控制每个组件显示的元素数目,max.level=显示对象的层次深度,默认值为NA,显示对象实际的层次深度
> str(nestlist, vec.len = 0)
List of 3
$ a:List of 2
..$ : num [1:5, 1:2] NULL ...
..$ val: num NULL ...
$ b:List of 2
..$ : chr [1:10] ...
..$ values: num [1:5] NULL ...
$ c:List of 2
..$ :List of 2
.. ..$ : int [1:10] NULL ...
.. ..$ : int [1:20] NULL ...
..$ :List of 2
.. ..$ : int [1:5] NULL ...
.. ..$ : int [1:10] NULL ...
> ##### 1.5 对象的转换
> #as.xxxxx转换对象
> x = c(1,2,3,4,5)
> list(x)
[[1]]
[1] 1 2 3 4 5
> as.list(x)
[[1]]
[1] 1
[[2]]
[1] 2
[[3]]
[1] 3
[[4]]
[1] 4
[[5]]
[1] 5
> ##### 1.6 缺失值
> #不带引号的NA代表一个缺失值,可以通过as,NA , is.NA来指定或者判断一个值为缺失值,注意NA和NULL的区别,NA表示一个占位,NULL则不占位
> x <- c(1,2,NA)
> length(x)
[1] 3
> y <- c(1,2,NULL)
> length(y)
[1] 2
posted on 2018-07-15 22:16 DataMaySpeak 阅读(38) 评论(0) 收藏 举报
浙公网安备 33010602011771号