标签: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]
标签:char integer each 改变 rod orange 个数 alpha UNC
原文地址:https://www.cnblogs.com/yellowall/p/9026159.html