Re: [R] A very simple question

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Wed, 14 May 2008 11:13:25 -0600

Use logical subscripts rather than which:

> k <- c(1,1,1,2,2,1,1,1)
> k[ k != 1 ]
[1] 2 2
> k[ k != 2 ]
[1] 1 1 1 1 1 1
> k[ k != 3 ]
[1] 1 1 1 2 2 1 1 1

Hope this helps,

--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow_at_imail.org
(801) 408-8111




> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Shubha
> Vishwanath Karanth
> Sent: Wednesday, May 14, 2008 9:16 AM
> To: r-help_at_stat.math.ethz.ch
> Subject: [R] A very simple question
>
> Hi R,
>
>
>
> Suppose
>
> l=c(1,1,1,2,2,1,1,1)
>
>
>
> k[-which(k==1)]
>
> [1] 2 2
>
>
>
> k[-which(k==2)]
>
> [1] 1 1 1 1 1 1
>
>
>
> But,
>
>
>
> k[-which(k==3)]
>
> numeric(0)
>
>
>
> I do not want this numeric(0), instead the whole k itself
> should be my result... How do I do this?
>
>
>
>
>
> Thanks,
>
> Shubha
>
>
>
> This e-mail may contain confidential and/or privileged
> i...{{dropped:13}}
>
> ______________________________________________
> 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.
>
______________________________________________ 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.
Received on Wed 14 May 2008 - 20:37:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 14 May 2008 - 21:30:44 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive