hairui@hadoop:~$ R
R version 3.4.4 (2018-03-15) -- "Someone to Lean On"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R是自由软件,不带任何担保。
在某些条件下你可以将其自由散布。
用'license()'或'licence()'来看散布的详细条件。
R是个合作计划,有许多人为之做出了贡献.
用'contributors()'来看合作者的详细情况
用'citation()'会告诉你如何在出版物中正确地引用R或R程序包。
用'demo()'来看一些示范程序,用'help()'来阅读在线帮助文件,或
用'help.start()'通过HTML浏览器来看帮助文件。
用'q()'退出R.
> revenue <- c(201451,214941,220185,197121,179431,187123,164877)
> active_players <- c (187421,197456,214784,201544,175446,187454,170154)
> mean(revenue)
[1] 195018.4
> mean(revenue)
[1] 195018.4
> mean(active_playesrs)
Error in mean(active_playesrs) : 找不到对象'active_playesrs'
> mean(active_players)
[1] 190608.4
> sd(revenue)
[1] 19535.76
> sd(active_players)
[1] 15380.33
> cor(revenue,active_players)
[1] 0.9014327
> plot(active_players,revenue)
> summary(revenue)
Min. 1st Qu. Median Mean 3rd Qu. Max.
164877 183277 197121 195018 208196 220185
> summary(active_players)
Min. 1st Qu. Median Mean 3rd Qu. Max.
170154 181434 187454 190608 199500 214784
> a <- c(1,3,5,7,9,13)
> b <- c("dau","wau","mau")
> c <- c(FALSE,FALSE,TRUE,TRUE)
> a[2]
[1] 3
> a[c(1,2,5)]
[1] 1 3 9
> a[2:5]
[1] 3 5 7 9
> y <- matrix(1:20,nrow=4,ncol=5)
> y
[,1] [,2] [,3] [,4] [,5]
[1,] 1 5 9 13 17
[2,] 2 6 10 14 18
[3,] 3 7 11 15 19
[4,] 4 8 12 16 20
> y2 <- matrix(1:20,nrow=4,ncol=5,byrow=TRUE)
> y2
[,1] [,2] [,3] [,4] [,5]
[1,] 1 2 3 4 5
[2,] 6 7 8 9 10
[3,] 11 12 13 14 15
[4,] 16 17 18 19 20
> y3 <- matrix(1:20,nrow=4,ncol=5,byrow=TRUE,dimnames=list(c("R1","R2","R3","R4"),c("C1","C2","C3","C4","C5")))
> y3
C1 C2 C3 C4 C5
R1 1 2 3 4 5
R2 6 7 8 9 10
R3 11 12 13 14 15
R4 16 17 18 19 20
> y3[3:5]
[1] 11 16 2
> y3[2,4]
[1] 9
> y3[2,2:5]
C2 C3 C4 C5
7 8 9 10
> dim1 <- c("A1","A2")
> dim2 <- c("B1","B2","B3")
> dim3 <- c("C1","C2","C3","C4")
> z <- array(1:24,c(2,3,4),dimnames=list(dim1,dim2,dim3))
> z
, , C1
B1 B2 B3
A1 1 3 5
A2 2 4 6
, , C2
B1 B2 B3
A1 7 9 11
A2 8 10 12
, , C3
B1 B2 B3
A1 13 15 17
A2 14 16 18
, , C4
B1 B2 B3
A1 19 21 23
A2 20 22 24
>
R语言入门简单练习
最新推荐文章于 2024-07-20 09:40:11 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)