[R] (no subject)

Stephen C. Upton upton at mitre.org
Sat Jan 18 16:11:03 CET 2003


I think you want to try using index vectors.
index <- c(1:length(x))
negs <- index[x<0]
nonnegs <- index[x>=0]

Then, if you want the negative values, just use
negativevalues <- x[negs]


Jmshttn at aol.com wrote:

> Dear Mailing List,
> If I wanted a data set of twenty standard normal results, I would type:
> x<-rnorm(20)
> If I then wanted to make all the negative results in that data set to be
> listed as zero I would then type in:
> x[x<0]<-0
> However, I now want to discard the values that are zero, but I want to know
> which values out of the original data set which I truncated to zeros I
> discarded. How is the best way of doing this? Do I use match(x,0) /
> (1:length(x))[x==0] ? How do I discard the values as well as wanting the
> original data set values. All suggestions would be greatly appreciated.
> Thank you,
> James Hutton
>         [[alternate HTML version deleted]]
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help

More information about the R-help mailing list