[R] Subset using partial values
David Winsemius
dwinsemius at comcast.net
Wed Mar 3 21:32:54 CET 2010
On Mar 3, 2010, at 9:04 AM, Newbie19_02 wrote:
>
> Thanks again for the help but what I am having trouble with is that
> I get:
>
> 1012 CAO0103166 01/04/1999 I200
> 1016 CAO0103166 03/05/2000 I200
> 1024 CAO0103166 20/06/1997 I209
> 1025 CAO0103166 25/02/1999 I209
> 1027 CAO0103166 27/08/1999 I200
> 1058 CAO0107171 11/01/2002 N411
> 1104 CAO0113512 14/02/2003 I209
Use the "^' (caret) to represent the beginning of a string.
> tdt[grepl("^410*|^I25*", tdt$main_condition), ]
ID PROCHI Date_admission main_condition
2 28394 CAO3121534 18/04/1999 I251
3 28395 CAO3121534 18/10/1993 4109
5 28397 CAO3121534 20/04/1999 I251
6 28398 CAO3121534 21/04/1999 I251
8 28400 CAO3121534 21/10/1993 4109
13 28405 CAO3121534 30/09/1997 I259
Or:
> subset(tdt, grepl("^410*|^I25*",main_condition))
ID PROCHI Date_admission main_condition
2 28394 CAO3121534 18/04/1999 I251
3 28395 CAO3121534 18/10/1993 4109
5 28397 CAO3121534 20/04/1999 I251
6 28398 CAO3121534 21/04/1999 I251
8 28400 CAO3121534 21/10/1993 4109
13 28405 CAO3121534 30/09/1997 I259
>
>
> I'm trying to avoid getting N411?
>
> Thanks,
> Natalie
> --
> View this message in context: http://n4.nabble.com/Subset-using-partial-values-tp1576614p1576683.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.
More information about the R-help
mailing list