我有一个if条件,后跟几个命令。但是,似乎存在语法错误,但它无法正常工作。我想这很容易。我四处寻找正确的文档,但没有找到解决方案。谢谢你的帮助!
#data
supply_by_gas <- rep(0,365)
supply_by_gas[] <- 32069547/365
overall_gas_prod <- 51224298
#here the condition which should be true
if (overall_gas_prod > sum(supply_by_gas))
#followed by two commands
{peak_use_gas <- (overall_gas_prod - sum(supply_by_gas))
overall_gas_prod <- sum(supply_by_gas)-1 }
else
{peak_use_gas <- 0}
这是我收到的错误:
Unexpected 'else' in "else"
> {peak_use_gas <- 0}
答案 0 :(得分:3)
if (overall_gas_prod > sum(supply_by_gas)) {
peak_use_gas <- (overall_gas_prod - sum(supply_by_gas))
overall_gas_prod <- sum(supply_by_gas)-1
} else {
peak_use_gas <- 0
}