mardi 26 février 2019

IF...ELSE in R Assistance

I am trying to write an If...Else statement in R and I am running into some difficulties. I have a data set that has 20 years of data and the values of VariableA need to be adjusted based on the specific year they are in (VariableB). I tried using an If...Else statement but I keep getting:

VariableA VariableB Multiplier VariableC 100 1998 1.4 140 100 1998 1.4 140 100 1999 1.7 170 100 1999 1.7 170 100 2000 2.0 200 100 2000 2.0 200

Error: unexpected '}' in " }"

The code that I have been trying to get to work is below:

Data <- function(DMG, YEAR){
if(YEAR = "1998"){
Data$TotDmg2017 <- Data$DMG * 1.433988335
}
}

I am not sure if this is the correct code to be using or if this is the most efficient way of doing this. I am unfamiliar with loops and If...Else statements so any assistance would be most appreciated.

Aucun commentaire:

Enregistrer un commentaire