Message-ID: <CADv2QyFE5J-50oyd6YoYm5qNU48RLLeA9AzfPPRNRu0-YPCSEA@mail.gmail.com>
Date: 2011-08-02T18:41:04Z
From: Dennis Murphy
Subject: Extract names from vector according to their values
In-Reply-To: <CACtaF7yVxf1O5SaGGGhXoVDXW5dW0gZNzV+LEsJ991szynNqjQ@mail.gmail.com>
Hi:
One more possibility:
> names(my.vector[grep('recommended', my.vector)])
[1] "Matrix" "boot" "class" "cluster" "codetools"
[6] "foreign" "KernSmooth" "lattice" "MASS" "Matrix"
[11] "mgcv" "nlme" "nnet" "rpart" "spatial"
[16] "survival"
> names(my.vector[grep('base', my.vector)])
[1] "base" "compiler" "datasets" "graphics" "grDevices" "grid"
[7] "methods" "splines" "stats" "stats4" "tcltk" "tools"
[13] "utils"
HTH,
Dennis
On Tue, Aug 2, 2011 at 11:21 AM, Sverre Stausland
<johnsen at fas.harvard.edu> wrote:
> Dear helpers,
>
> I can create a vector with the priority of the packages that came with
> R, like this:
>
>> installed.packages()[,"Priority"]->my.vector
>> my.vector
> ? ? ? ? base ? ? ? ? ?boot ? ? ? ? class ? ? ? cluster ? ? codetools
> ? ? ? "base" "recommended" "recommended" "recommended" "recommended"
> ? ? compiler ? ? ?datasets ? ? ? foreign ? ? ?graphics ? ? grDevices
> ? ? ? "base" ? ? ? ?"base" "recommended" ? ? ? ?"base" ? ? ? ?"base"
> ? ? ? ? grid ? ?KernSmooth ? ? ? lattice ? ? ? ? ?MASS ? ? ? ?Matrix
> ? ? ? "base" "recommended" "recommended" "recommended" "recommended"
> ? ? ?methods ? ? ? ? ?mgcv ? ? ? ? ?nlme ? ? ? ? ?nnet ? ? ? ? rpart
> ? ? ? "base" "recommended" "recommended" "recommended" "recommended"
> ? ? ?spatial ? ? ? splines ? ? ? ? stats ? ? ? ?stats4 ? ? ?survival
> "recommended" ? ? ? ?"base" ? ? ? ?"base" ? ? ? ?"base" "recommended"
> ? ? ? ?tcltk ? ? ? ? tools ? ? ? ? utils
> ? ? ? "base" ? ? ? ?"base" ? ? ? ?"base"
>
> How can I extract the names from this vector according to their
> priority? I.e. I want to create a vector from this with the names of
> the "base" packages, and another vector with the names of the
> "recommended" packages.
>
> Thank you
> Sverre
>
> ______________________________________________
> 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.
>