Reputation: 627
I'm running the following in R:
if (mito$count > 1) {
mito$Polymorphism <- "SNP"
} else if ((mito$count == 1) & (mito$A_GT == mito$ref | mito$C_GT == mito$ref | mito$G_GT == mito$ref | mito$T_GT == mito$ref)) {
mito$Polymorphism <- "No"
} else {
mito$Polymorphism <- ""
}
And its giving me the usual error that everyone seems to get:
1: In if (mito$count > 1) { :
the condition has length > 1 and only the first element will be used
2: In if ((mito$count == 1) & (mito$A_GT == mito$ref | mito$C_GT == :
the condition has length > 1 and only the first element will be used
I assume this has to do with single value vs a vector (the former, I want to do). Is there something I need to specify the data frame as beforehand?
Upvotes: 1
Views: 266
Reputation: 627
ifelse()
worked in this situation:
mito$Polymorphism <- ifelse(mito$count > 1,
'SNP',
ifelse(((mito$count == 1) &
(mito$A_GT == mito$ref |
mito$C_GT == mito$ref |
mito$G_GT == mito$ref |
mito$T_GT == mito$ref)),
'NO',
''))
Upvotes: 2