R语言基础
载入一些常用的包:
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))
The Safest Way to Get what you Want is to Try and Deserve What you Want.