[R] turning list into vector/dataframe

Alain Guillet alain.guillet at uclouvain.be
Fri Apr 10 13:00:09 CEST 2009


Hi Melissa,

L <- list(min=rnorm(5),mean=rnorm(5),max=rnorm(5))
matrix(unlist(L),ncol=3)

gives what you want


Alain



Melissa2k9 wrote:
> Hi,
>
> I have used this command :
>
> resamples<-lapply(1:1000,function(i) sample(lambs,replace=F))
> resamples2<-lapply(resamples,Cusum)
>
> to get a list of 1000 samples of my data. The function Cumsum is defined as
> follows:
>
> Cusum<-function(x){
> SUM<-cumsum(x)-(1:length(x))*mean(x)
> min<-min(cumsum(x)-(1:length(x))*mean(x))
> max<-max(cumsum(x)-(1:length(x))*mean(x))
> diff<-max-min
> ans<-c(min,max,diff)
> ans
> }
>
>
> where lambs is a vector of temperatures.
>
> An example of part of my list is:
>
> [[998]]
> [1] -5.233176  6.903034 12.136210
>
> [[999]]
> [1] -9.296690  1.516233 10.812922
>
> [[1000]]
> [1] -1.502066e+01 -4.547474e-13  1.502066e+01
>
> Now I want to convert this list into a dataframe so for example 1000 rows
> with col names Min, Max and Diff. My supervisor said I first had to turn
> this into a vector but I don't seem to be able to do that!
>
> Any ideas on how to turn this list into a dataframe would be really
> appreciated :) Thanks in advance
>
> Melissa
>   

-- 
Alain Guillet
Statistician and Computer Scientist

SMCS - Institut de statistique - Université catholique de Louvain
Bureau d.126
Voie du Roman Pays, 20
B-1348 Louvain-la-Neuve
Belgium

tel: +32 10 47 30 50




More information about the R-help mailing list