码迷,mamicode.com
首页 > 其他好文 > 详细

R-introduction

时间:2018-05-12 00:02:04      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:char   integer   each   改变   rod   orange   个数   alpha   UNC   

length(x)  # 给出元素个数
prod(x) #给出元素积
sum(x)#元素和
mean(x)=sum(x)/length(x)
var(x)=sum((x-mean(x))^2/(length(x)-1)
sort(x) #按升序重新排列

seq(1,10,length=10,by=2)

> labs <- paste(c("x","y"),1:10,sep="")
> labs
 [1] "x1"  "y2"  "x3"  "y4"  "x5"  "y6"  "x7"  "y8"  "x9"  "y10"

 2.7索引向量

1.逻辑向量

> y <- x[!is.na(x)]

!is.na(x)输出都是true false,从总选取true的值

2.正整数向量

索引向量是length的子向量

x[5]

x[1:10]

> c("x","y")[rep(c(1,2,2,1), times=4)]

#必须是c函数的

3.负整数向量

> y <- x[-(1:5)]

4.字符串向量

> fruit <- c(5, 10, 1, 20)
> names(fruit) <- c("orange", "banana", "apple", "peach")
> lunch <- fruit[c("apple","orange")]

> y[y < 0] <- -y[y < 0]  等价于> y <- abs(y)

3.1内在属性

> z <- 0:9

> z<- as.character(z)

> d <- as.integer(z)

3.2改变对象长度

> length(alpha) <- 3

> alpha <- alpha[2 * 1:5]

 

R-introduction

标签:char   integer   each   改变   rod   orange   个数   alpha   UNC   

原文地址:https://www.cnblogs.com/yellowall/p/9026159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!