【发布时间】:2017-08-09 23:05:50
【问题描述】:
我是 R 新手,我需要帮助从我的数据集中获取一些值。该信息是城市列表中每年的美元金额。我正在尝试设置我的值,以便我可以对整个数据集名称估计值运行线性回归模型。
estimate <- read.csv("estimate.csv", check.names = FALSE) #Import
estimate
location 2010 2011 2012 2013 2014
city1 200 250 300 500 600
city2 300 300 400 650 780
city3 500 600 700 800 900
我只对 city3 的年展数据感兴趣。
我知道我可以使用代码 years <- c(2010,2011,2012,2013,2014) 来创建我的年份变量,但我知道这仅适用于小表。
对于我的线性模型,我想首先 plot(years, values) 其中年份是 2:6 列,对应的值仅来自第 3 行。当我运行values <- estimate[3, c(3,2:6] 时,我得到了值的数据,但是当我尝试为years <- estimate[0, c(0,2:6)] 做同样的事情时,我得到一个包含 5 个变量的 0 对象。试图情节给我
Error in plot.window(...) : need finite 'xlim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) : no non-missing arguments to max; returning -In
理想情况下,我希望数据设置在:
years values
2010 500
2011 600
2012 700
2013 800
2014 900
然后我可以运行 lm 函数。提前谢谢。我对 R 和 Stack 中的这些东西真的很陌生,所以请原谅我的新手。
【问题讨论】:
-
reshape::melt(estimate),然后是子集
标签: r linear-regression