Skip to content
Back to formatted view

Raw Message

Message-ID: <9DDB15CF23B35C4CBED7DEB8C6B63A7396DDDC@SERVER1.distinctconsulting.ie>
Date: 2009-04-24T10:44:05Z
From: Bronagh Grimes
Subject: Array
In-Reply-To: <49F19711.7050503@biostat.ku.dk>

Thanks for this, will have a look now.

Much appreciated,

-----Original Message-----
From: Peter Dalgaard [mailto:P.Dalgaard at biostat.ku.dk] 
Sent: 24 April 2009 11:40
To: Bronagh Grimes
Cc: r-help at r-project.org
Subject: Re: [R] Array

Bronagh Grimes wrote:

> Just wondering if anyone has any tips for using arrays?

You're presupposing that R works like SAS. It doesn't.

This looks like a job for reshape (either Hadley Wickham's package or
the built-in function).

> I am trying to convert the following SAS code to R: 

> data A2;  
>  set A1;   
>  by subject_id;
>  retain   BX1-BX10    i; 
>  array b(1:10) BX1-BX10 ;
>  if first.subject_id then do ;
>       do j=1 to 10;
>        b(j) = .;    
>       end;
>       i=1;
>  end;
>  b(i)  =  BX;
>  i = i+1;
>  if last.subject_id then output;
> run ;

-- 
   O__  ---- Peter Dalgaard             ?ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907