R语言常用命令

Dataframe相关

#CSV读取
info_original<-read.csv("info.csv")

#浏览 data frame 
str(any_data_frame)

#条件筛选行
any_data_frame[which(any_data_frame$col_name == condition_value)]

#快速看dataframe常用统计结论
print(summary(any_data_frame))

#分类别统计
aggregate(x=any_data_frame$aim_col_name,by = list(any_data_frame$category),FUN=mean)

#join 或 merge 两个data frame
merge(info_original,troop_original,by=c("server_life","location","r_kind"),all = TRUE)

代码编辑相关

with(all_data,
     lohar_rate <- lohar_dau / dau,
     guardian_rate <- guardian_dau / dau,
     fort_rate <- fort_dau/dau,
     barbarian_rate <- barbarian_dau / dau  
)

绘制相关

#图片大小设置
options(repr.plot.width=20, repr.plot.height=10)

#ggplot基本用法
ggplot(all_data,aes(server_life,barbarian_rate))+geom_line()

#ggplot控制坐标轴范围
+coord_cartesian(xlim =c(5, 20), ylim = c(0, 50))

字符串处理

#字符串拼接
paste("a","bad",sep="")

CSV输入输出

#输入
action_original<-read.csv("合集.csv")

#输出
write.csv(all_data,file = "temp_output.csv",quote=F,row.names = F)

发表评论