Note: forwarded message attached.
                
---------------------------------
--- 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>&nbsp;</div>  
<div>attach(fram)<BR>dset1&lt;-cbind(AGE,BMI,DEATH)<BR>BMIGRP1&lt;-cut(BMI,breaks=c(14,20,25,57),right=TRUE)<BR>levels(BMIGRP1)<BR>BMIGRP&lt;-as.numeric(BMIGRP1)<BR>AGEGRP&lt;-floor(AGE/10)-2<BR>dset&lt;-cbind(AGEGRP,BMIGRP,DEATH)<BR>maxage&lt;-max(dset[,1])<BR>minage&lt;-min(dset[,1])<BR>maxcls&lt;-max(dset[,2],
 
na.rm=T)<BR>mincls&lt;-min(dset[,2],na.rm=T)<BR>nage&lt;-maxage-minage+1<BR>nclass&lt;-maxcls-mincls+1<BR>nsub&lt;-nrow(dset)<BR>weight
 &lt;- matrix(,nage,1)<BR>for ( i in minage:maxage )<BR>&nbsp; 
{weight[i-minage+1,1] = sum(std = i)}</div>  <div>&nbsp; atrisk = 
matrix(,nclass,nage)<BR>&nbsp; wevents = matrix(,nclass,nage)<BR>#reduce data 
set to frequency table <BR>&nbsp;for( i in (minage : maxage))<BR>&nbsp;for( j 
in (mincls :
 
maxcls))<BR>#atrisk1&lt;-aggregate(dset[,c("AGEGRP","BMIGRP")],list(RANDID=dset1$RANDID,sum)</div>
  <div>&nbsp;&nbsp;&nbsp; {atrisk[j-mincls+1,i-minage+1] 
=<BR>&nbsp;&nbsp;&nbsp;&nbsp; sum((dset[,1]=i)&amp; 
(dset[,2]=j))<BR>&nbsp;&nbsp;&nbsp; 
wevents[j-mincls+1,i-minage+1]=<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
sum((dset[,1]=i)&amp; (dset[,2]=j)&amp;(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>&nbsp;</div>  <div><BR><BR><B><I>Petr Pikal &lt;[EMAIL 
PROTECTED]&gt;</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&lt;-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>&gt; As my earlier email said I am not getting the maxcls. I 
do get numbers<BR>&gt; coded as 1,2,3 for BMIGRP(when I print BMIGRP) but not 
getting the max<BR>&gt; of (1,2,3) which should be 3, I guess.<BR>&gt; <BR>&gt; 
Thanks for your help<BR>&gt; Anamika<BR>&gt; <BR>&gt; <BR>&gt; Anamika 
Chaudhuri <[EMAIL PROTECTED]>wrote:<BR>&gt; &gt; 
dset1&lt;-cbind(AGE,BMI,DEATH)<BR>&gt; &gt; 
BMIGRP&lt;-cut(BMI,breaks=c(14,20,25,57),right=TRUE)<BR>&gt; &gt; 
levels(BMIGRP)<BR>&gt; [1] "(14,20]" "(20,25]" "(25,57]"<BR>&gt; &gt;
 BMIGRP1&lt;-as.numeric(BMIGRP)<BR>&gt; &gt; AGEGRP&lt;-floor(AGE/10)-2<BR>&gt; 
&gt; dset&lt;-cbind(AGEGRP,BMIGRP1,DEATH)<BR>&gt; &gt; 
maxage&lt;-max(dset[,1])<BR>&gt; &gt; minage&lt;-min(dset[,1])<BR>&gt; &gt; 
maxcls&lt;-max(dset[,2])<BR>&gt; &gt; maxcls<BR>&gt; [1] NA<BR>&gt; <BR>&gt; 
Why doesnt it give me a no for maxcls then?<BR>&gt; <BR>&gt; Thanks.<BR>&gt; 
<BR>&gt; <BR>&gt; "Richard M. Heiberger" <[EMAIL PROTECTED]>wrote:<BR>&gt; &gt; 
x &lt;- rnorm(100)<BR>&gt; &gt; xx &lt;- cut(x,3)<BR>&gt; &gt; 
levels(xx)<BR>&gt; [1] "(-2.37,-0.716]" "(-0.716,0.933]" "(0.933,2.58]" 
<BR>&gt; &gt; as.numeric(xx)<BR>&gt; <BR>&gt; <BR>&gt; 
---------------------------------<BR>&gt; <BR>&gt; <BR>&gt; <BR>&gt; 
---------------------------------<BR>&gt; <BR>&gt; [[alternative HTML version 
deleted]]<BR>&gt; <BR>&gt; 
______________________________________________<BR>&gt; [email protected] 
mailing list<BR>&gt; https://stat.ethz.ch/mailman/listinfo/r-help<BR>&gt; 
PLEASE do read the posting
 guide!<BR>&gt; 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 ---
______________________________________________
[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

Reply via email to