赞
踩
本文的主要来源是R语言中的dplyr、plyr、reshape、reshape2
用于data.frames中的all.equal
> desc(1:10)
[1] -1 -2 -3 -4 -5 -6 -7 -8 -9 -10
> desc(factor(letters))
[1] -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18
[19] -19 -20 -21 -22 -23 -24 -25 -26
> first_day <- seq(as.Date("1910/1/1"), as.Date("1920/1/1"), "years")
> first_day
[1] "1910-01-01" "1911-01-01" "1912-01-01" "1913-01-01" "1914-01-01"
[6] "1915-01-01" "1916-01-01" "1917-01-01" "1918-01-01" "1919-01-01"
[11] "1920-01-01"
> desc(first_day)
[1] 21915 21550 21185 20819 20454 20089 19724 19358 18993 18628 18263
> lead(1:10, 1)
[1] 2 3 4 5 6 7 8 9 10 NA
> lead(1:10, 2)
[1] 3 4 5 6 7 8 9 10 NA NA
> lag(1:10, 1)
[1] NA 1 2 3 4 5 6 7 8 9
> changes(mtcars, mtcars)
<identical>
> changes(mtcars, mtcars2)
Changed variables:
old new
cyl2 <added> 002598E8
Changed attributes:
old new
names 270C1148 26FAC3E0
row.names 289F5628 1887A080
class 0F87A5F0 09954BC0
x <- sample(1:10, 1e5, rep = TRUE)
x
length(unique(x))
n_distinct(x)
> x <- 10:1
> y <- 1:10
> order_by(x,cumsum(y))
[1] 55 54 52 49 45 40 34 27 19 10
> x <- 10:1
> y <- 1:10
> y
[1] 1 2 3 4 5 6 7 8 9 10
> x
[1] 10 9 8 7 6 5 4 3 2 1
> count(baseball[1:100,], vars = "id")
id freq
1 ansonca01 8
2 bennech01 1
3 burdoja01 7
4 forceda01 9
5 galvipu01 1
6 gerhajo01 5
7 hinespa01 6
8 jonesch01 6
9 mathebo01 7
10 morrijo01 2
11 nelsoca01 5
12 orourji01 6
13 shaffor01 4
14 snydepo01 5
15 startjo01 7
16 suttoez01 7
17 whitede01 7
18 yorkto01 7
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。