[R] list output
Erin Hodgess
erinm.hodgess at gmail.com
Thu Mar 26 19:22:14 CET 2015
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]]
More information about the R-help
mailing list