0

Table Details with new column position

I have this table in which contain two columns (1st = names, 2nd =Positions*). I want add a 3rd column titled"GeneName" which should have the values according to $position column. As if the position value falls in any of the undermentioned class related GeneName should be written in the new column. 3 names to be filled in the new column are NIb, VPg and CI. Conditions are

NIb = from position 1014 to 2410
VPg = 3660 to 5563 and 
CI  = 5718 to 6282

Please see the image attached for better understanding.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Stat Bio
  • 1
  • 1
  • 2

1 Answers1

0

I did this using ifelse statement multiple times.

fg$GeneName<-ifelse(fg$position_by_miRanda>=1014 & fg$position_by_miRanda<=2410,"NIb",fg$GeneName)

fg$GeneName<-ifelse(fg$position_by_miRanda>=3660 & fg$position_by_miRanda<=5563,"CI",fg$GeneName)

fg$GeneName<-ifelse(fg$position_by_miRanda>=5718 & fg$position_by_miRanda<=6282,"VPg",fg$GeneName)
Stat Bio
  • 1
  • 1
  • 2
  • 1
    You don't need to assign every condition separately. You can do a [nested ifelse](http://stackoverflow.com/questions/18012222/nested-ifelse-statement-in-r) – Sotos Oct 20 '16 at 09:08