Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find if each row of a logical matrix has at least one TRUE

Tags:

r

matrix

is there some way to convert this data:

        (Intercept) Timecoursecdc15 Timecoursecdc28 Timecourseclb Timecoursecln
YAL001C       FALSE           FALSE           FALSE         FALSE         FALSE
YAL002W       FALSE           FALSE           FALSE         FALSE         FALSE
YAL003W       FALSE           FALSE           FALSE         FALSE         FALSE
YAL004W       FALSE           FALSE           FALSE         FALSE         FALSE
YAL005C       FALSE           FALSE           FALSE         FALSE         FALSE
YAL007C       FALSE           FALSE           FALSE         FALSE          TRUE

to something like this:

  YPR163C   YPR164W   YPR165W   YPR166C   YPR167C   YPR168W   YPR169W   YPR170C 
    FALSE     FALSE     FALSE      TRUE     FALSE     FALSE     FALSE     FALSE 
  YPR171W   YPR172W   YPR173C   YPR174C   YPR175W   YPR176C   YPR177C   YPR178W 
    FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE 
  YPR179C   YPR180W   YPR181C   YPR182W   YPR183W   YPR184W   YPR185W   YPR186C 
    FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE 
  YPR187W   YPR188C   YPR189W   YPR190C   YPR191W   YPR192W   YPR193C   YPR194C 
    FALSE     FALSE     FALSE      TRUE     FALSE     FALSE     FALSE     FALSE 
  YPR195C   YPR196W   YPR197C   YPR198W   YPR199C   YPR200C   YPR201W   YPR202W 
    FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE     FALSE

So, looking at the values of each row, if any row contains TRUE, then YAL007C is TRUE.

like image 799
user2886545 Avatar asked Nov 28 '22 09:11

user2886545


1 Answers

Like this:

rowSums(dat) > 0L

which will be a lot faster than using a loop or apply...

like image 156
flodel Avatar answered Dec 28 '22 06:12

flodel