jpm miao
2013-May-08 01:54 UTC
[R] How can I find negative items from a vector with a short command?
Hi, I have a vector f with some negative columns. I remember that there is an easy expression that can find out negative items. Can someone tell me how I can do it? It seems to be f[i such that f[i]<0 ...] Thanks, Miao> d<-1:7 > f<-(-2)^d > f[1] -2 4 -8 16 -32 64 -128 [[alternative HTML version deleted]]
Pascal Oettli
2013-May-08 02:06 UTC
[R] How can I find negative items from a vector with a short command?
Hi, The solution can be easily found on Internet. By the way, the following does what you are looking for: > f[f<0] Regards, Pascal On 05/08/2013 10:54 AM, jpm miao wrote:> Hi, > > I have a vector f with some negative columns. I remember that there is > an easy expression that can find out negative items. Can someone tell me > how I can do it? > > It seems to be > f[i such that f[i]<0 ...] > > Thanks, > > Miao > >> d<-1:7 >> f<-(-2)^d >> f > [1] -2 4 -8 16 -32 64 -128 > > [[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. >
Jorge I Velez
2013-May-08 02:09 UTC
[R] How can I find negative items from a vector with a short command?
f [ f < 0 ] On Wed, May 8, 2013 at 11:54 AM, jpm miao <miaojpm@gmail.com> wrote:> Hi, > > I have a vector f with some negative columns. I remember that there is > an easy expression that can find out negative items. Can someone tell me > how I can do it? > > It seems to be > f[i such that f[i]<0 ...] > > Thanks, > > Miao > > > d<-1:7 > > f<-(-2)^d > > f > [1] -2 4 -8 16 -32 64 -128 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]