r {:条件有长度> 1
这是我第一次在Stackoverflow中问一个问题,也是我第一次使用R进行编码 因此,请了解我的解释是否不清楚:(
我现在有一个数据框(Data2000),即1092 x 6 标题是年,月份,预测范围,公司名称,GDP价格指数和消费者价格指数
< img src =“ https://i.sstatic.net/gooqg.png” alt =“在此处输入图像说明”>
我想在GDPPI和CPI上创建每个月的矢量,
我的最终目标是获得卑鄙,中位数,四分位数范围和每个月的第90个百分位数范围,我认为这是第一步
,这是我写的代码,
***library(tidyverse)
data2000 <- read.csv("")
for (i in 1:12) {
i_gdppi <- c()
i_cpi <- c()
}
for (i in 1:12) {
if (data2000$month == i) {
append(i_gdppi,data2000[,gdppi])
append(i_cpi, data2000[,cpi])
}
}***
不幸的是,我收到了一条错误消息,说 if(data2000 $ month == 1){:条件的错误; 1
我自己搜索了它,在if语句中,我不能将矢量用作条件 我该如何解决这个问题? 非常感谢您,祝您有美好的一天!
this is my first time asking a question in StackOverflow and also my first time coding using R
So, please understand if my explanation is unclear :(
I now have a data frame (data2000) that is 1092 x 6
The headers are year, month, predictive horizon, name of the company, GDP Price Index, and Consumer Price Index
I want to create vectors on gdppi and cpi for each month
My ultimate goal is to get the mean, median, interquartile range, and 90th-10th percentile range for each month and I thought this is the first step
and this is the code that I wrote by far
***library(tidyverse)
data2000 <- read.csv("")
for (i in 1:12) {
i_gdppi <- c()
i_cpi <- c()
}
for (i in 1:12) {
if (data2000$month == i) {
append(i_gdppi,data2000[,gdppi])
append(i_cpi, data2000[,cpi])
}
}***
Unfortunately, I got an error message saying that
Error in if (data2000$month == 1) { : the condition has length > 1
I googled it by myself and in if statement, I cannot use a vector as a condition
How can I solve this problem?
Thank you so much and have a nice day!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用
group_by()
函数,则它需要按下子设置:则给予此信息,然后
group_by(年,月份)
如果您有几年和几个月,
If you use the
group_by()
function then it takes care of sub-setting your data:Gives this
If you have years and months, then
group_by(year, month)