R base常用函数
1. paste函数可以连接多个字符串
eg:
> paste("zyy",today,".csv",sep = "_")
[1] "zyy_20160701_.csv"
注:若sep = "“的话,结果为:"zyy 20160701 .csv" (中间是有空格的)
2. write.table函数
完整用法:write.table( x, file = "", append = FALSE, quote = TRUE, sep = " ", eol = "\n", na = "NA", dec = ".", row.names = TRUE, col.names = TRUE, qmethod = c("escape", "double"), fileEncoding = "")
eg:
write.table(dfStatistics,paste("/opt/zhang/2016/statics/20160701/",today,element,".txt"),quote = FALSE,row.names = FALSE,col.names = FALSE)
result: (4rows4cols)
-0.0588332758241705 0.453240375020587 0.993221448231117 1183
0.00405424653716224 0.485046650445398 0.990729232283876 1184
-0.0147157745266746 0.579237723308444 0.993420215229189 1162
-0.0709399766666685 0.521929306049231 0.994288488632102 1170
3. 获取当前日期
eg:
> now <- Sys.Date()
> now
[1] "2016-11-24"
> format(now,"%Y%m%d")
[1] "20161124"
> format(now,"%Y年%m月%d日")
[1] "2016年11月24日"
4. expand.grid函数,用来输出数据框
5.merge函数
执行 merge函数时,函数自动会找到两个数据框df1和df2 共有的列,即id那一列(即相当于 by= "id"),当参数 all= FALSE时, 会将两个数据框中该列数值相等的那些行输出来,类似于对这两个数据框的id这一列求交集(intersection)。
————————————————
本文来源:https://blog.csdn.net/weixin_37833125/article/details/70209175
相关文章