[R] Need help for logical expression

roslinazairimah zakaria ro@lin@ump @ending from gm@il@com
Mon Jan 7 06:23:42 CET 2019


Dear all,

I just have a simple problem here.

I generate a sample data as follows:
set.seed(123456)
r1 <- sample(1:100,100 ,replace=T)
r2 <- sample(1:100,100 ,replace=T)
r3 <- sample(1:100,100 ,replace=T)

R <- cbind(r1,r2,r3); head(R)
> R <- cbind(r1,r2,r3); head(R)
     r1 r2 r3
[1,] 80  4 20
[2,] 76 66 14
[3,] 40 32 87
[4,] 35 19 24
[5,] 37 63 12
[6,] 20 52 42
sum_r <- rowSums(R)
all_pct <- round(R/sum_r*100,0); head(all_pct)
> all_pct <- round(R/sum_r*100,0); head(all_pct)
     r1 r2 r3
[1,] 77  4 19
[2,] 49 42  9
[3,] 25 20 55
[4,] 45 24 31
[5,] 33 56 11
[6,] 18 46 37

I would like to count how many of all_pct data satisfy this condition as
follows:

dt_all <- ifelse(all_pct[,1] >= 45 & all_pct[,1] > all_pct[,2] &
all_pct[,1] > all_pct[,3], 1, 0)

Note that data of all_pct[,1] >= 45  and at the same time greater
than all_pct[,2] and all_pct[,3].

How do I count how many satisfy the conditions?

-- 
*Roslinazairimah Zakaria*
*Tel: +609-5492370; Fax. No.+609-5492766*

*Email: roslinazairimah using ump.edu.my <roslinazairimah using ump.edu.my>;
roslinaump using gmail.com <roslinaump using gmail.com>*
Faculty of Industrial Sciences & Technology
University Malaysia Pahang
Lebuhraya Tun Razak, 26300 Gambang, Pahang, Malaysia

	[[alternative HTML version deleted]]



More information about the R-help mailing list