1.数据的导入
用于导入数据的R函数:
.使用R包自带数据
.读取csv文件:read.table和它的cousins
.不规则数据:readLines
.读取excel文件:xlsx包/read.xlsx
.读取spss文件:foreign包/read.spss
.读取sas文件:read.ssd
2.不规范数据的预处理
见代码:
#############download data from website, unzip data########
#############read data from mutiple separate files
#美国国际开发署开发政府公开的原始数据
download.file(url="http://jaredlander.com/data/US_Foreign_Aid.zip",
destfile="ForeignAid.zip")
unzip("ForeignAid.zip")
library(stringr)
dir()
theFiles=dir(pattern = "^US_Foreign_Aid")
theFiles
?regex
#loop through those files
for (a in theFiles)
{
#build a good name to assign to data
nameToUse=str_sub(string=a,start=12,end