一/數(shù)據(jù)集的合并
(一)、Merge函數(shù)
merge(a,b,by = '列名',by.x,by.y,all=True) ——a,b是合并的數(shù)據(jù)框,by按什么合并,all是否保留所有行,all.x=True是a中所有行,b中匹配的行 all.y=True是b中所有的行,a中匹配的行?
(二)、cbind函數(shù)
cbind(a,b)——縱向鏈接兩個數(shù)據(jù)框,行相同
(三)、rbind函數(shù)
rbind(a,b)——橫向鏈接兩個數(shù)據(jù)框,列相同
(四)、duplicated(h)——返回邏輯值,看是否前面有相同的行 h[!duplicated(h),]返回沒重復(fù)的行
(五)、排序函數(shù)
sort(age)——對age數(shù)列,從小到大排序
sort(age,decreasing=T)——從大到小排序
order(age)——從小到大排序返回每個的索引
rank(age)——返回序列每個值排第幾
怎么按某列從小到大排序呢?數(shù)據(jù)集[order,]
sort(x,na.last=T)——讓缺失值排最后 若F則排最前 若NA則直接刪掉
t(a)——對a轉(zhuǎn)置
(六)、aggregate函數(shù)
aggregate(處理的列,by = list(),算法)——按list分類對列求均值
(七)、抽樣函數(shù)
sample(1:100,10)——在1到100抽10個數(shù)
sample(letters[1:20],10,replace=T)——有放回抽樣,replace默認(rèn)F