[R] force apply() to return a list

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.be
Mon Nov 21 09:52:54 CET 2005


I've also changed the f() function, i.e.,

f <- function(x){list(1:max(x[1], 4))}


I hope it'll work now.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm



----- Original Message ----- 
From: "Robin Hankin" <r.hankin at noc.soton.ac.uk>
To: "Dimitris Rizopoulos" <dimitris.rizopoulos at med.kuleuven.be>
Cc: "Robin Hankin" <r.hankin at noc.soton.ac.uk>; 
<r-help at stat.math.ethz.ch>
Sent: Monday, November 21, 2005 9:40 AM
Subject: Re: [R] force apply() to return a list


> Hi Dimitris
>
>
> On 21 Nov 2005, at 08:37, Dimitris Rizopoulos wrote:
>> out <- lapply(apply(a2, 1, f), "[[", 1)
>
>
> thanks for this, but it doesn't quite do what I want:
>
>
> > f <- function(x){1:max(x[1],4)}
> > lapply(apply(cbind(1:5,5:1), 1, f), "[[", 1)
> [[1]]
> [1] 1
>
> [[2]]
> [1] 1
>
> [[3]]
> [1] 1
>
> [[4]]
> [1] 1
>
> [[5]]
> [1] 1
>
> >
>
> I want
>
>> [[1]]
>> [1] 1 2 3 4
>>
>> [[2]]
>> [1] 1 2 3 4
>>
>> [[3]]
>> [1] 1 2 3 4
>>
>> [[4]]
>> [1] 1 2 3 4
>>
>> [[5]]
>> [1] 1 2 3 4 5
>
>
>
> best wishes
>
> Robin
>
>
>
>
> --
> Robin Hankin
> Uncertainty Analyst
> National Oceanography Centre, Southampton
> European Way, Southampton SO14 3ZH, UK
>  tel  023-8059-7743
> 


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm




More information about the R-help mailing list