Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Like this:

rowSums(dat) > 0L

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...