Hi All, I have a character vector of length=700. The vector contains names and I want to extract the names that contain the number 101. The number 101 could be anywhere within the name. what is the best way to do this? -- View this message in context: http://www.nabble.com/How-to-extract-names-from-a-vector-tp25773482p25773482.html Sent from the R help mailing list archive at Nabble.com.
See ?grep On Tue, Oct 6, 2009 at 2:48 PM, kayj <kjaja27 at yahoo.com> wrote:> > Hi All, > > I have a character vector of length=700. ?The vector contains names and I > want to extract the names that contain the number 101. ?The number 101 could > be anywhere within the name. > > what is the best way to do this? > > -- > View this message in context: http://www.nabble.com/How-to-extract-names-from-a-vector-tp25773482p25773482.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
vec <- 1:700
names(vec) <- 700:1
names(vec)[grep("101", names(vec))]
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at
r-project.org]
> On Behalf Of kayj
> Sent: Tuesday, October 06, 2009 12:49 PM
> To: r-help at r-project.org
> Subject: [R] How to extract names from a vector
>
>
> Hi All,
>
> I have a character vector of length=700. The vector contains names and I
> want to extract the names that contain the number 101. The number 101
> could
> be anywhere within the name.
>
> what is the best way to do this?
>
> --
> View this message in context: http://www.nabble.com/How-to-extract-names-
> from-a-vector-tp25773482p25773482.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.