Re: [R] looking for a string

From: [Ricardo Rodriguez] Your XEN ICT Team <>
Date: Wed, 16 Apr 2008 14:01:22 +0200

Thanks Mark!

Mark Leeds wrote:
> Hi Ricardo: you can look at ?regexpr but I'm pretty sure that below returns
> a vector of TRUES and FALSES depending on whether the condition ( is Jalapa
> contained in unidad ) is TRUE. So, wherever the vector is TRUE is where
> Jalapa was contained in unidad. So, it's basically EXACTLY the same
> as what Henrique did. I just can't remember exactly what Henrique did
> at the moment.
> regexpr("Jalapa", as.character( unidad ) ) != -1
> So, suppose your dataframe was called DF and it has column called unidad.
> Then,
> newDF<-DF[(regexpr("Jalapa", as.character( unidad ) ) != -1),]
> should be a new dataframe , exactly the same as the old one, but only
> containing the rows where the condition was true. Does that clear things up
> for you ?

Yes. It is clear for me now. Thanks for your detailed explanation!
> The expression is for the rows and has the TRUES and FALSES as a
> vector and whenever it is TRUE, the row is kept and whatever is FALSE, the
> row is not kept. The comma just says to take all the columns.
> You can also use subset directly if that's easier for you the same way
> you figured out how to use it in the state.77 example.
> If it's not clear, it's because you need to understand how logical
> subscripting is used in R. For that, I think the thing to read is
> "Introduction to R" which is one of the documents at
> Do

Yes, this is the main problem: I need to understand basic concepts. And I am aware that logical subscripting is not one of my strengths. The example has also forced me to understand another basic concetp: attach() and detach()! I didn't know why unidad was not available just by name in my environment. I used to call variables as name$dataframe.
> temp<- regexpr("Jalapa", as.character( unidad ) ) != -1
> print(temp)
> to see exactly what regexpr does.

Thanks again.



Ricardo Rodríguez
Your XEN ICT Team

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 16 Apr 2008 - 12:31:05 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Apr 2008 - 13:30:30 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive