If I understand correctly what you want to do, I can think of several ways to do it; here are two:
> y <- x <- rnorm(20)
> neg <- x < 0
> x[neg] <- 0
> x
[1] 0.7314066 0.3515410 0.0000000 0.0000000
[5] 0.0000000 0.0000000 0.0000000 0.0000000
[9] 0.4341421 0.0000000 0.2766616 0.1823935
[13] 0.0000000 0.0000000 0.0000000 0.0000000
[17] 0.0000000 1.3797720 1.2607272 0.6471086
> x[!neg]
[1] 0.7314066 0.3515410 0.4341421 0.2766616
[5] 0.1823935 1.3797720 1.2607272 0.6471086
> (1:20)[neg]
[1] 3 4 5 6 7 8 10 13 14 15 16 17
>
> neg <- which(y < 0)
> y[neg] <- 0
> neg
[1] 3 4 5 6 7 8 10 13 14 15 16 17
> y[-neg]
[1] 0.7314066 0.3515410 0.4341421 0.2766616
[5] 0.1823935 1.3797720 1.2607272 0.6471086
I hope that this helps,
John
At 09:32 AM 1/18/2003 -0500, [EMAIL PROTECTED] 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]] ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help
----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: [EMAIL PROTECTED] phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- ______________________________________________ [EMAIL PROTECTED] mailing list http://www.stat.math.ethz.ch/mailman/listinfo/r-help