取出一個數字序列中的百分位數
1. 求某一個百分比
x<-rnorm(200) quantile(x,0.9)
2. 求一系列的百分比
quantile(x,c(0.1,0.9))
quantile(x,seq(0.1,1,0.1))
3. 只取數值:unname()。去掉百分符號
unname(quantile(x,0.9))
4. 多數值,去重復
unique(quantile(x, probs = seq(0,1, length.out = 50)))
cut函數將一列點划分到各自的區間里。
如有1000個學生的考試分數(滿分100),想要按照分數評等級,
如果是均勻划分(90-100,80-90,70-80,...),直接做除法取商就行,
但如果划分不均勻(90-100,75-90,60-75,0-60), cut函數將會派上用場。
c0=c(2.3,3,1.5,4.8,9,3,4,7,8,9.5) cuttime=c(0,3,6,9,10) cut(c0,cuttime,labels = F,right = F)
隨機取樣
sample(seq(1:10),2)
給定一組邏輯值,是否所有的值都為True
Given a set of logical vectors, are all of the values true?
all(c(T,F))
數據的中心化和標准化
scale is generic function whose default method centers and/or scales the columns of a numeric matrix.
就是假設數據服從正態分布,然后有一個標准化的公式。
options(digits=3) data <- c(1, 2, 3, 6, 3) scale(data, center=T,scale=F) scale(data, center=T,scale=T)
do.call
list <- list(matrix(1:25, ncol = 5), matrix(4:28, ncol = 5), matrix(21:45, ncol=5)) list.sum<-do.call(sum,list) list.sum<-do.call(cbind,list)
do.call() 是告訴list一個函數,然后list里的所有元素來執行這個函數。
