[R] for-loop ?

Deepayan Sarkar deepayan at stat.wisc.edu
Sat Dec 7 01:13:03 CET 2002


On Friday 06 December 2002 05:27 pm, Christian Schulz wrote:
> ...why the loop produce NA's ?
>
> >>test[i] <- for (i in 1:30) {
>
> +       healthy(i)
> +       }
>
> >>test
>
>  [1]  0 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
> NA NA
> [26] NA NA NA NA  0


You probably want to do


test <- numeric(30)

for (i in 1:30) {
    test[i] <- healthy(i)
}

-Deepayan




More information about the R-help mailing list