Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #49287
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Selecting items in a vector |
| Date | 2016-07-21 20:44 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <nmrc7v$ahp$1@dont-email.me> (permalink) |
| References | <nmr2t3$5s2$1@dont-email.me> <nmr39b$79e$1@dont-email.me> |
WJ wrote: > WJ wrote: > > > R: > > > > Create a vector of random integers: > > > > > sample(-3:5, 22, rep=TRUE) -> v > > > v > > [1] 5 2 -3 2 4 -1 -2 -3 -3 -1 4 4 -1 0 0 -2 -2 1 2 0 0 3 > > > > Find the indices at which v < 0: > > > > > which(v < 0) > > [1] 3 6 7 8 9 10 13 16 17 > > > > Extract the negative numbers: > > > > > v[which(v < 0)] > > [1] -3 -1 -2 -3 -3 -1 -1 -2 -2 > > > > How much easier is it in ANS Forth? > > That was regrettable newbie prolixity. > > > v<0 > [1] FALSE FALSE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE FALSE FALSE > [13] TRUE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE > > v[v<0] > [1] -3 -1 -2 -3 -3 -1 -1 -2 -2 Change all values < 0 to 90: > v[v<0] = 90 > v [1] 5 2 90 2 4 90 90 90 90 90 4 4 90 0 0 90 90 1 2 0 0 3
Back to comp.lang.forth | Previous | Next — Previous in thread | Find similar | Unroll thread
Selecting items in a vector "WJ" <w_a_x_man@yahoo.com> - 2016-07-21 18:05 +0000
Re: Selecting items in a vector "WJ" <w_a_x_man@yahoo.com> - 2016-07-21 18:11 +0000
Re: Selecting items in a vector "WJ" <w_a_x_man@yahoo.com> - 2016-07-21 20:44 +0000
csiph-web