if statement - R: How to use IF correctly? -
i have 2 columns of values this:
>bb gdis bdis 1 12.291488 8.009909 2 11.283319 13.625103 3 6.674549 8.629232 4 13.493121 17.175888 5 9.550731 9.867878 6 9.193895 9.785301 7 10.541702 10.941371 8 9.849527 9.496284 9 8.682287 8.133774 10 8.439381 4.335260
i need add column , call index
calculates ratio gdis/bdis
if gdis
bigger, , bdis/gdis
if bdis
bigger.
how do that?
try
transform(bb, index=ifelse(gdis>bdis, gdis/bdis, bdis/gdis)) # gdis bdis adn #1 12.291488 8.009909 1.534535 #2 11.283319 13.625103 1.207544 #3 6.674549 8.629232 1.292856 #4 13.493121 17.175888 1.272937 #5 9.550731 9.867878 1.033207 #6 9.193895 9.785301 1.064326 #7 10.541702 10.941371 1.037913 #8 9.849527 9.496284 1.037198 #9 8.682287 8.133774 1.067436 #10 8.439381 4.335260 1.946684
Comments
Post a Comment