全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
3436 7
2016-02-05
The U.S. Gasoline Market, 52 Yearly Observations, 1953-2004
Source: These data were compiled by Professor Chris Bell, Department of Economics, University of North Carolina, Asheville. Sources: www.bea.gov and www.bls.gov

    * Year = Year, 1953-2004,
    * GasExp = Total U.S. gasoline expenditure,
    * Pop = U.S. total population in thousands
    * GasP = Price index for gasoline,
    * Income = Per capita disposable income,
    * Pnc = Price index for new cars,
    * Puc = Price index for used cars,
    * Ppt = Price index for public transportation,
    * Pd = Aggregate price index for consumer durables,
    * Pn = Aggregate price index for consumer nondurables,
    * Ps = Aggregate price index for consumer services.



Year,GasExp,Pop,Gasp,Income,PNC,PUC,PPT,PD,PN,PS
   1953.00       7.40000       159565.       16.6680       8883.00   
   47.2000       26.7000       16.8000       37.7000       29.7000   
   19.4000   

以上为数据截取,
> read.table("C:/Users/forYear/Documents/R/工作/2014Homework1_datasets/Gasoline.txt", header = FALSE, sep = "", skip = 18)
>Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  line 3 did not have 5 elements

因为11个变量,在txt里分为了三行排列,所以不能使用上述命令,应该怎么解决这一个问题

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-2-5 20:49:09
建议上传部分文件哈
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-2-6 11:37:20
jiangbeilu 发表于 2016-2-5 20:49
建议上传部分文件哈
Gasoline.txt
大小:(8.91 KB)

 马上下载


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-2-6 12:27:49
rawlines <- readLines(file(".../Gasoline.txt"))
rawlines2 = rawlines[19:length(rawlines)]

names = unlist(strsplit(rawlines[18], ","))

lines <- paste(rawlines2[c(TRUE, FALSE, FALSE)], rawlines2[c(FALSE, TRUE, FALSE)],
               rawlines2[c(FALSE, FALSE, TRUE)], collapse = "\n")
data <- read.table(text = lines, na.string = "*")

names(data) = names
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-2-6 16:03:04
提示: 作者被禁止或删除 内容自动屏蔽
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-3-29 09:37:10
使用 infile v1 v2 v3 "路径" 格式输入,希望能帮到你,可用help infile 查看
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群