C <- rep(c('F','M'), each = 3, times = 4)
Gender <- NULL
for (i in C) {
if i == 'F'{
append(Gender,values = 'Female')
}
else {
append(Gender, values = 'Male')
}
}
and it shows Error: unexpected '}' in " }"
what should I fix in this code?
CodePudding user response:
The error comes from if i == 'F'
C <- rep(c('F','M'), each = 3, times = 4)
Gender <- NULL
for (i in C) {
if (i == 'F'){ # The condition has to be wrapped by ()
Gender <- append(Gender,values = 'Female') # Reassign to Gender
} else { # It's better to put else this way
Gender <- append(Gender, values = 'Male')
}
}