[R] Selecting numbers not divisible by 3

Rui Barradas ruipbarradas at sapo.pt
Thu Mar 27 13:17:00 CET 2014


Hello,

Inline.

Em 27-03-2014 11:32, Pascal Oettli escreveu:
> Hello,
>
> Something like that?
>
> R> X <- 1:100
> R> Y <- X %% 3
> R> Y <- ifelse(Y==0, TRUE, FALSE)

The ifelse here is not needed, you can simply do

Y <- Y == 0

Rui Barradas

> R> X[Y]
>   [1]  3  6  9 12 15 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 66 69 72 75
> [26] 78 81 84 87 90 93 96 99
>
> HTH,
> Pascal
>
> On Thu, Mar 27, 2014 at 6:23 PM, Prabhakar Ghorpade
> <dr.prabhakar08 at gmail.com> wrote:
>> Hi,
>> here's my code
>>
>> X <- 1:100
>>
>> I want to select number divisible by 3 out of them how can I select it?
>>
>> ( I tried following
>> X <- 1:100
>> DIV <- Y - > X/3
>>
>> But I am getting whole number and number with fractions. WHole intgers are
>> my number of interest from original X. How can I traceback to number
>> divisbile by 3. ?)
>>
>> Thanks
>>
>> Kind Regards,
>> Prabhakar
>>
>>
>>
>> --
>> Dr.Ghorpade Prabhakar B.
>> Ph.D. Scholar ( Animal Biochemistry)
>> Indian Veterinary Research Institute.
>> India
>>
>>
>>
>> --
>> Dr.Ghorpade Prabhakar B.
>> Ph.D. Scholar ( Animal Biochemistry)
>> Indian Veterinary Research Institute.
>> India
>>
>>          [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
>




More information about the R-help mailing list