1 : ifelse(expression,value1,value2)
2:select_(iris, .dots = list(quote(-Petal.Length), quote(-Petal.Width)))
select 和 select_?
select
select(iris, starts_with("Petal"))
select(iris, ends_with("Width"))
select(iris, contains("etal"))
select(iris, matches(".t."))
select(iris, Petal.Length, Petal.Width)
可以通過各種方式定義想要篩選的列名
select_
Programming with select ---------------------------------------------------
select_(iris, ~Petal.Length)
select_(iris, "Petal.Length")
select_(iris, lazyeval::interp(~matches(x), x = ".t."))
select_(iris, quote(-Petal.Length), quote(-Petal.Width))
select_(iris, .dots = list(quote(-Petal.Length), quote(-Petal.Width)))
3:append()
1.如何往list某列末尾添加數(shù)據(jù)锌唾?
直接用append(某list,要寫入的數(shù)據(jù))
append(x, values, after = length(x))
Arguments
xthe vector to be modified.
valuesto be included in the modified vector.計(jì)劃貼入的對(duì)象
aftera subscript, after which the values are to be appended.表示想在x中貼的位置
舉例:
例一:
> L1
$p1
[1] 2 3 4 5
$p2
[1] 10 11 12 13 14 15
> append(L1$p1,13)
[1] ?2 ?3 ?4 ?513
例二:
> append(1:5, 0:1,after = 3)
[1] 1 2 30 14 5
4:同樣可以進(jìn)行數(shù)據(jù)擴(kuò)展的還有transmute()函數(shù),與mutate()函數(shù)不同的是,該函數(shù)擴(kuò)展新變量的同時(shí)擅笔,將刪除所有原始變量泡孩。
dplyr
dplyr包的5個(gè)函數(shù)可以有效的執(zhí)行數(shù)據(jù)處理的大部分任務(wù),分別如下:
select:用于選取一列或者多列
filter:用于選取特定條件下的某些行
arrange:用于實(shí)現(xiàn)數(shù)據(jù)一列或多列的升降排序
mutate:用于在數(shù)據(jù)集中添加列
summarise:用于實(shí)現(xiàn)數(shù)據(jù)匯總
data.table
data.table包提供了一個(gè)非常簡(jiǎn)潔的通用格式:DT[i,j,by]净嘀,可以理解為:對(duì)于數(shù)據(jù)集DT轩褐,選取子集行i,通過by分組計(jì)算j
顏色版
colorRampPalette(c("blue","white"))(10)
自定義色系椎咧,漸變色
gray(0:10/10)