[R] subsetting from a vector or matrix
andrew
andrewjohnroyal at gmail.com
Fri Sep 25 09:10:36 CEST 2009
both the following will probably do the trick.
?subset
?"["
Basically on the second one, you want to come down to something that
looks like
x[L]
where x is a matrix/vector, and L is a logical vector that has the
same dimension as x, but is TRUE on the values of x that you want to
select.
for instance
x <- rnorm(100000)
L <- x > 3
x[L] will return all values of x that are greater than 3.
or you can just do
x[x>3]
On Sep 25, 9:45 am, "Jim Bouldin" <jrboul... at ucdavis.edu> wrote:
> I realize this should be simple but I'm having trouble subsetting vectors
> and matrices, for example extracting all values meeting a certain
> criterion, from a vector. Cannot seem to figure out the correct syntax and
> help page not very helpful. Or should I be using some other function than
> subset. Thanks for any help.
>
> Jim Bouldin
>
> ______________________________________________
> R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list