Skip to content
Back to formatted view

Raw Message

Message-ID: <1359661113.17886.YahooMailNeo@web142603.mail.bf1.yahoo.com>
Date: 2013-01-31T19:38:33Z
From: arun
Subject: Locate Patients who have multiple high blood pressure readings
In-Reply-To: <CAJ=kPNv2GPMExe2Epd8MKpX5NLH7sjt8qiA+oL-_vzUKWiLrqg@mail.gmail.com>

Hi,

May be this helps:

#dd
res<-data.frame(Include=with(subset(dd,OBS_TYPE == "SBP" & Blood_Pressure >= 140|OBS_TYPE=="DBP" & Blood_Pressure>=90),apply(tapply(Blood_Pressure,list(PT_ID,OBS_TYPE),length)>=2,1,any,na.rm=T)))
res
?# ?? Include
#1900??? TRUE
#2900?? FALSE
#3900?? FALSE
A.K.




----- Original Message -----
From: Weijia Wang <wwang.nyu at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Thursday, January 31, 2013 10:51 AM
Subject: [R] Locate Patients who have multiple high blood pressure readings

On Thu, Jan 31, 2013 at 10:29 AM, Weijia Wang <wwang.nyu at gmail.com> wrote:

> Hi,
>
>
>
> I have a new question about subsetting in R.
>
>
>
> Say we have this data frame:
>
>
>
>? ?  PT_ID Blood_Pressure OBS_TYPE
>
> 92?  1900? ? ? 90.0? ? ? DBP
>
> 94?  1900? ? ? 90.0? ? ? DBP
>
> 174? 2900? ?  140.0? ? ? SBP
>
> 176? 2900? ?  130.0? ? ? SBP
>
> 180? 3900? ?  120.0? ? ? SBP
>
> 268? 3900? ?  150.0? ? ? SBP
>
> 268? 3900? ? ? 90.0? ? ? DBP
>
>
>
> I need to obtain those with 2+ DBP>=90 or 2+ SBP>=140.
>
>
>
> PT_ID=1900, he has 2 DBP>=90, so he will be included.
>
> PT_ID=2900, he has 1 SBP>=140, so he will NOT be included.
>
> PT_ID=3900, he has 1 SBP>=140 and 1 DBP>=90, so he will still NOT be
> included.
>
>
>
> So, the condition requires TWO OR MORE values higher than the threshold.
> It could be either SBP or DBP or both of them.
>
>
>
> I have tried ddply, but I don?t know how to add the condition 2+ inside
> ddply.
>
>
>
> Any help is appreciated!!
>
>
>
> Weijia
>
>
>

??? [[alternative HTML version deleted]]


______________________________________________
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.