Hi there, Just wondering if anyone has any tips for using arrays? 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 ; Many thanks in advance, Bronagh [[alternative HTML version deleted]]
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
Bronagh Grimes wrote:> Hi there, > > > > Just wondering if anyone has any tips for using arrays? > > > > I am trying to convert the following SAS code to R: >You're probably going to get more useful responses in general if, instead of posting code from SAS to be ported to R, you describe what the code is doing (e.g., give some sample input, and describe what you'd like the output to be). That way, you do not limit those who will reply to the set of people who know SAS. Many times, the concepts will be different between the two approaches one would take when programming something in SAS and R.