[From nobody Wed Apr 26 21:53:17 2006
Received: from [24.61.251.1] by web34101.mail.mud.yahoo.com via HTTP;
	Wed, 26 Apr 2006 12:39:51 PDT
Date: Wed, 26 Apr 2006 12:39:50 -0700 (PDT)

Subject: Re: [R] Help needed
To: Petr Pikal &lt;petr.pikal@precheza.cz&gt;
In-Reply-To: &lt;444F39D1.19913.274373@localhost&gt;
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=&quot;0-1025507389-1146080390=:92916&quot;
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&lt;-cbind(AGE,BMI,DEATH)
BMIGRP1&lt;-cut(BMI,breaks=c(14,20,25,57),right=TRUE)
levels(BMIGRP1)
BMIGRP&lt;-as.numeric(BMIGRP1)
AGEGRP&lt;-floor(AGE/10)-2
dset&lt;-cbind(AGEGRP,BMIGRP,DEATH)
maxage&lt;-max(dset[,1])
minage&lt;-min(dset[,1])
maxcls&lt;-max(dset[,2], na.rm=T)
mincls&lt;-min(dset[,2],na.rm=T)
nage&lt;-maxage-minage+1
nclass&lt;-maxcls-mincls+1
nsub&lt;-nrow(dset)
weight &lt;- 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&lt;-aggregate(dset[,c(&quot;AGEGRP&quot;,&quot;BMIGRP&quot;)],list(RANDID=dset1$RANDID,sum)
      {atrisk[j-mincls+1,i-minage+1] =
     sum((dset[,1]=i)&amp; (dset[,2]=j))
    wevents[j-mincls+1,i-minage+1]=
      sum((dset[,1]=i)&amp; (dset[,2]=j)&amp;(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 &lt;petr.pikal@precheza.cz&gt; wrote:
  Hi

you experienced difference between matrix (cbind(....)) and data 
frame (data.frame(......)) or you have some NA value in your BMIGRP1

try:
maxcls&lt;-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: &quot;Richard M. Heiberger&quot; , r-help@stat.math.ethz.ch
Subject: Re: [R] Help needed

&gt; As my earlier email said I am not getting the maxcls. I do get numbers
&gt; coded as 1,2,3 for BMIGRP(when I print BMIGRP) but not getting the max
&gt; of (1,2,3) which should be 3, I guess.
&gt; 
&gt; Thanks for your help
&gt; Anamika
&gt; 
&gt; 
&gt; Anamika Chaudhuri wrote:
&gt; &gt; dset1&lt;-cbind(AGE,BMI,DEATH)
&gt; &gt; BMIGRP&lt;-cut(BMI,breaks=c(14,20,25,57),right=TRUE)
&gt; &gt; levels(BMIGRP)
&gt; [1] &quot;(14,20]&quot; &quot;(20,25]&quot; &quot;(25,57]&quot;
&gt; &gt; BMIGRP1&lt;-as.numeric(BMIGRP)
&gt; &gt; AGEGRP&lt;-floor(AGE/10)-2
&gt; &gt; dset&lt;-cbind(AGEGRP,BMIGRP1,DEATH)
&gt; &gt; maxage&lt;-max(dset[,1])
&gt; &gt; minage&lt;-min(dset[,1])
&gt; &gt; maxcls&lt;-max(dset[,2])
&gt; &gt; maxcls
&gt; [1] NA
&gt; 
&gt; Why doesnt it give me a no for maxcls then?
&gt; 
&gt; Thanks.
&gt; 
&gt; 
&gt; &quot;Richard M. Heiberger&quot; wrote:
&gt; &gt; x &lt;- rnorm(100)
&gt; &gt; xx &lt;- cut(x,3)
&gt; &gt; levels(xx)
&gt; [1] &quot;(-2.37,-0.716]&quot; &quot;(-0.716,0.933]&quot; &quot;(0.933,2.58]&quot; 
&gt; &gt; as.numeric(xx)
&gt; 
&gt; 
&gt; ---------------------------------
&gt; 
&gt; 
&gt; 
&gt; ---------------------------------
&gt; 
&gt; [[alternative HTML version deleted]]
&gt; 
&gt; ______________________________________________
&gt; R-help@stat.math.ethz.ch mailing list
&gt; https://stat.ethz.ch/mailman/listinfo/r-help
&gt; PLEASE do read the posting guide!
&gt; http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal@precheza.cz



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

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