[R] list output
peter dalgaard
pdalgd at gmail.com
Thu Mar 26 19:41:00 CET 2015
Erin,
I think you'll have heard people requesting _reproducible_ examples several times by now... This one isn't.
Offhand, I'd suspect that the issue has to do with your single-bracket indexing of the list "out". Try out[[i]].
-Peter
> On 26 Mar 2015, at 19:22 , Erin Hodgess <erinm.hodgess at gmail.com> wrote:
>
> Hello!
>
> I am having some trouble with some list output.
>
> Here is my code:
> geobunch <- function(y) {
>
> out <- vector("list",3)
> aic <- numeric(length=3)
> print(str(out))
> for(i in 1:3) {
>
> x <- geomin(y,i)
> print(i)
> print(x)
> print(str(x))
> out[i]$phi_0 <- x$phi_0
> out[i]$maxlike <- x$maxlike
> out[i]$bigp <- x$bigp
> aic[i] <- -2*out[i]$maxlike + (2*(i+1))
> }
> minaic <- which(aic==min(aic))
> minout <- out[unlist(minaic)]
> return(minout)
> }
>
> And here is the output:
>> geobunch(ez2a)
> List of 3
> $ : NULL
> $ : NULL
> $ : NULL
> NULL
> [1] 1
> $phi_0
> [1] 2.856428
>
> $bigp
> [1] 0.1584016
>
> $maxlike
> [1] -473.0203
>
> List of 3
> $ phi_0 : num 2.86
> $ bigp : num 0.158
> $ maxlike: num -473
> NULL
> Error in aic[i] <- -2 * out[i]$maxlike + (2 * (i + 1)) :
> replacement has length zero
> In addition: Warning messages:
> 1: In out[i]$phi_0 <- x$phi_0 :
> number of items to replace is not a multiple of replacement length
> 2: In out[i]$maxlike <- x$maxlike :
> number of items to replace is not a multiple of replacement length
> 3: In out[i]$bigp <- x$bigp :
> number of items to replace is not a multiple of replacement length
>>
>
> I know that the problem is in how I am setting up the "out" variable, but
> I'm not sure how to correct it. Also, the bigp variable can take on
> different lengths.
>
> This is on R version 3.1.3, on Ubuntu 14.04.
>
> Thank you so much for any help.
>
> Sincerely,
> Erin
>
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodgess at gmail.com
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
More information about the R-help
mailing list