jeudi 22 mars 2018

if else Function R

Greetings R profesionales,

Having a lot of trouble with using if function in R, any help would be greatly appreciated.

I am trying to add another column onto the 'p5' data frame, each number in the 'position' column represents a single mutation in a chromosome, I want the new column to show the functional domains of the mutations i.e. 'Z-disk', 'I-band etc. I've tried multiple variations of code and keep on getting this error:

the condition has length > 1 and only the first element will be used

p5$Functional.Domain <- if (p5$position < 179400576) {
    as.character("M-Band")
}
else if (p5$position < 179483218) {
    as.character("A-Band")
}
else if (p5$position < 179639929) {
    as.character("I-Band")
}
else {
    as.character("Z-disk")
}

dput():

structure(list(p4.position = c(179395822, 179400405, 179401029, 
179403522, 179403566, 179404286, 179404491, 179406990, 179408239, 
179410544, 179410799, 179411339, 179412245, 179412902, 179413187, 
179414153, 179414506, 179416474, 179416530, 179416531, 179417723, 
179418418, 179419765, 179422231, 179422249, 179422457, 179422725, 
179423314, 179424036, 179424398, 179424496, 179424782, 179425091, 
179426073, 179426074, 179427963, 179428086, 179428871, 179429468, 
179429849, 179430371, 179430544, 179432420, 179433213, 179433407, 
179433665, 179433758, 179434009, 179435468, 179438874, 179440067, 
179440319, 179441015, 179441649, 179441870, 179442238, 179442324, 
179442793, 179443339, 179444429, 179444661, 179452242, 179452411, 
179452435, 179453427, 179454576, 179454957, 179455112, 179455162, 
179456704, 179457005, 179457392, 179458075, 179458085, 179462634, 
179463684, 179466263, 179469477, 179469738, 179470359, 179471841, 
179472127, 179472155, 179472209, 179477004, 179477169, 179477885, 
179478861, 179478864, 179481600, 179485012, 179485829, 179487411, 
179497039, 179497076, 179498055, 179506963, 179558736, 179591957, 
179604264, 179605063, 179605941, 179632576, 179634455, 179644174, 
179658189, 179658211)), .Names = "p4.position", row.names = c(NA, 
-107L), class = "data.frame")

Aucun commentaire:

Enregistrer un commentaire