--- Begin Message ---
Subject: Re: [R] Help needed
To: Petr Pikal <[EMAIL PROTECTED]>
In-Reply-To: <[EMAIL PROTECTED]>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary="0-1025507389-1146080390=:92916"
Content-Transfer-Encoding: 8bit
Content-Length: 2488
--0-1025507389-1146080390=:92916
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Thanks a lot.
How could I change the following code in SAS macro to R (the part marked in
red)?
Thanks so much!
attach(fram)
dset1<-cbind(AGE,BMI,DEATH)
BMIGRP1<-cut(BMI,breaks=c(14,20,25,57),right=TRUE)
levels(BMIGRP1)
BMIGRP<-as.numeric(BMIGRP1)
AGEGRP<-floor(AGE/10)-2
dset<-cbind(AGEGRP,BMIGRP,DEATH)
maxage<-max(dset[,1])
minage<-min(dset[,1])
maxcls<-max(dset[,2], na.rm=T)
mincls<-min(dset[,2],na.rm=T)
nage<-maxage-minage+1
nclass<-maxcls-mincls+1
nsub<-nrow(dset)
weight <- matrix(,nage,1)
for ( i in minage:maxage )
{weight[i-minage+1,1] = sum(std = i)}
atrisk = matrix(,nclass,nage)
wevents = matrix(,nclass,nage)
#reduce data set to frequency table
for( i in (minage : maxage))
for( j in (mincls : maxcls))
#atrisk1<-aggregate(dset[,c("AGEGRP","BMIGRP")],list(RANDID=dset1$RANDID,sum)
{atrisk[j-mincls+1,i-minage+1] =
sum((dset[,1]=i)& (dset[,2]=j))
wevents[j-mincls+1,i-minage+1]=
sum((dset[,1]=i)& (dset[,2]=j)&(dset[,3]=1))}
vtit = char(t(mincls:maxcls),5,0) // {Total};
htit = {'at risk' 'events' 'rate/1000'};
*;
atrisk2 = atrisk // atrisk[+,1:nage];
event2 = wevents // wevents[+,1:nage];
atrisk3 = choose(atrisk2=0,1,atrisk2);
rate = event2/atrisk3;
Petr Pikal <[EMAIL PROTECTED]> wrote:
Hi
you experienced difference between matrix (cbind(....)) and data
frame (data.frame(......)) or you have some NA value in your BMIGRP1
try:
maxcls<-max(dset[,2], na.rm=T)
if you have some NA values
or use
str(dset) to look what types are your variables.
HTH
Petr
On 25 Apr 2006 at 18:16, Anamika Chaudhuri wrote:
Date sent: Tue, 25 Apr 2006 18:16:42 -0700 (PDT)
From: Anamika Chaudhuri
To: "Richard M. Heiberger" , [email protected]
Subject: Re: [R] Help needed
> As my earlier email said I am not getting the maxcls. I do get numbers
> coded as 1,2,3 for BMIGRP(when I print BMIGRP) but not getting the max
> of (1,2,3) which should be 3, I guess.
>
> Thanks for your help
> Anamika
>
>
> Anamika Chaudhuri wrote:
> > dset1<-cbind(AGE,BMI,DEATH)
> > BMIGRP<-cut(BMI,breaks=c(14,20,25,57),right=TRUE)
> > levels(BMIGRP)
> [1] "(14,20]" "(20,25]" "(25,57]"
> > BMIGRP1<-as.numeric(BMIGRP)
> > AGEGRP<-floor(AGE/10)-2
> > dset<-cbind(AGEGRP,BMIGRP1,DEATH)
> > maxage<-max(dset[,1])
> > minage<-min(dset[,1])
> > maxcls<-max(dset[,2])
> > maxcls
> [1] NA
>
> Why doesnt it give me a no for maxcls then?
>
> Thanks.
>
>
> "Richard M. Heiberger" wrote:
> > x <- rnorm(100)
> > xx <- cut(x,3)
> > levels(xx)
> [1] "(-2.37,-0.716]" "(-0.716,0.933]" "(0.933,2.58]"
> > as.numeric(xx)
>
>
> ---------------------------------
>
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
[EMAIL PROTECTED]
---------------------------------
Celebrate Earth Day everyday! Discover 10 things you can do to help slow
climate change. Yahoo! Earth Day
--0-1025507389-1146080390=:92916
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
<div>Thanks a lot.</div> <div>How could I change the following code in SAS
macro to R (the part marked in red)?</div> <div>Thanks so much!</div>
<div> </div>
<div>attach(fram)<BR>dset1<-cbind(AGE,BMI,DEATH)<BR>BMIGRP1<-cut(BMI,breaks=c(14,20,25,57),right=TRUE)<BR>levels(BMIGRP1)<BR>BMIGRP<-as.numeric(BMIGRP1)<BR>AGEGRP<-floor(AGE/10)-2<BR>dset<-cbind(AGEGRP,BMIGRP,DEATH)<BR>maxage<-max(dset[,1])<BR>minage<-min(dset[,1])<BR>maxcls<-max(dset[,2],
na.rm=T)<BR>mincls<-min(dset[,2],na.rm=T)<BR>nage<-maxage-minage+1<BR>nclass<-maxcls-mincls+1<BR>nsub<-nrow(dset)<BR>weight
<- matrix(,nage,1)<BR>for ( i in minage:maxage )<BR>
{weight[i-minage+1,1] = sum(std = i)}</div> <div> atrisk =
matrix(,nclass,nage)<BR> wevents = matrix(,nclass,nage)<BR>#reduce data
set to frequency table <BR> for( i in (minage : maxage))<BR> for( j
in (mincls :
maxcls))<BR>#atrisk1<-aggregate(dset[,c("AGEGRP","BMIGRP")],list(RANDID=dset1$RANDID,sum)</div>
<div> {atrisk[j-mincls+1,i-minage+1]
=<BR> sum((dset[,1]=i)&
(dset[,2]=j))<BR>
wevents[j-mincls+1,i-minage+1]=<BR>
sum((dset[,1]=i)& (dset[,2]=j)&(dset[,3]=1))}</div> <div><FONT
color=#ff0000>vtit = char(t(mincls:maxcls),5,0) // {Total};<BR>htit = {'at
risk' 'events' 'rate/1000'};<BR>*;<BR>atrisk2 = atrisk //
atrisk[+,1:nage];<BR>event2 = wevents // wevents[+,1:nage];<BR>atrisk3 =
choose(atrisk2=0,1,atrisk2);<BR>rate = event2/atrisk3;</FONT></div>
<div> </div> <div><BR><BR><B><I>Petr Pikal <[EMAIL
PROTECTED]></I></B> wrote:</div> <BLOCKQUOTE class=replbq
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px
solid">Hi<BR><BR>you experienced difference between matrix (cbind(....)) and
data <BR>frame (data.frame(......)) or you have some NA
value in your BMIGRP1<BR><BR>try:<BR>maxcls<-max(dset[,2], na.rm=T)<BR>if
you have some NA values<BR>or use<BR>str(dset) to look what types are your
variables.<BR><BR>HTH<BR>Petr<BR><BR><BR>On 25 Apr 2006 at 18:16, Anamika
Chaudhuri wrote:<BR><BR>Date sent: Tue, 25 Apr 2006 18:16:42 -0700
(PDT)<BR>From: Anamika Chaudhuri <[EMAIL PROTECTED]><BR>To: "Richard M.
Heiberger" <[EMAIL PROTECTED]>, [email protected]<BR>Subject: Re: [R]
Help needed<BR><BR>> As my earlier email said I am not getting the maxcls. I
do get numbers<BR>> coded as 1,2,3 for BMIGRP(when I print BMIGRP) but not
getting the max<BR>> of (1,2,3) which should be 3, I guess.<BR>> <BR>>
Thanks for your help<BR>> Anamika<BR>> <BR>> <BR>> Anamika
Chaudhuri <[EMAIL PROTECTED]>wrote:<BR>> >
dset1<-cbind(AGE,BMI,DEATH)<BR>> >
BMIGRP<-cut(BMI,breaks=c(14,20,25,57),right=TRUE)<BR>> >
levels(BMIGRP)<BR>> [1] "(14,20]" "(20,25]" "(25,57]"<BR>> >
BMIGRP1<-as.numeric(BMIGRP)<BR>> > AGEGRP<-floor(AGE/10)-2<BR>>
> dset<-cbind(AGEGRP,BMIGRP1,DEATH)<BR>> >
maxage<-max(dset[,1])<BR>> > minage<-min(dset[,1])<BR>> >
maxcls<-max(dset[,2])<BR>> > maxcls<BR>> [1] NA<BR>> <BR>>
Why doesnt it give me a no for maxcls then?<BR>> <BR>> Thanks.<BR>>
<BR>> <BR>> "Richard M. Heiberger" <[EMAIL PROTECTED]>wrote:<BR>> >
x <- rnorm(100)<BR>> > xx <- cut(x,3)<BR>> >
levels(xx)<BR>> [1] "(-2.37,-0.716]" "(-0.716,0.933]" "(0.933,2.58]"
<BR>> > as.numeric(xx)<BR>> <BR>> <BR>>
---------------------------------<BR>> <BR>> <BR>> <BR>>
---------------------------------<BR>> <BR>> [[alternative HTML version
deleted]]<BR>> <BR>>
______________________________________________<BR>> [email protected]
mailing list<BR>> https://stat.ethz.ch/mailman/listinfo/r-help<BR>>
PLEASE do read the posting
guide!<BR>> http://www.R-project.org/posting-guide.html<BR><BR>Petr
Pikal<BR>[EMAIL PROTECTED]<BR><BR></BLOCKQUOTE><BR><p>
<hr size=1>Celebrate Earth Day everyday! Discover 10 things
you can do to help slow climate change. <a
href="http://us.rd.yahoo.com/mail_us/taglines/earthday/*http://earth.yahoo.com">Yahoo!
Earth Day</a>
--0-1025507389-1146080390=:92916--
--- End Message ---