-9

我有一个 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}
4

1 回答 1

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
}
于 2012-07-03T21:22:46.730 回答