首页 > 编程语言 > 详细

R语言基础

时间:2018-06-20 12:32:27      阅读:234      评论:0      收藏:0      [点我收藏+]

载入一些常用的包:

library(dplyr)
library(ggplot2)
library(statsr)

载入数据:

data(arbuthnot) 

查看数据:

arbuthnot 

查看数据维度:

dim(arbuthnot)

我的输出为: [1]  82  3 .

查看变量名:

names(arbuthnot)

 得到的输出:

[1] "year"  "boys"  "girls"

函数range: range(data$year)。查看变量的范围。
dataset$new_column <- dataset$column1 -+ dataset$column2

 画图:

present$total <- present$boys + present$girls
present$prop_boys <- present$boys / present$total
ggplot(data = present, aes(x=year,y=boys/total)) + 
  geom_line() + geom_point()

 

加列:

arbuthnot <- arbuthnot %>%
  mutate(total = boys + girls)

  

加边以及降序排列,present是数据集。

present %>%
  mutate(total=girls+boys) %>%
  arrange(desc(total))

  

 

R语言基础

原文:https://www.cnblogs.com/Shinered/p/9203023.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!