Skip to content
Back to formatted view

Raw Message

Message-ID: <200212061812.48453.deepayan@stat.wisc.edu>
Date: 2002-12-07T01:13:03Z
From: Deepayan Sarkar
Subject: for-loop ?
In-Reply-To: <005701c29d7f$0fdacc40$4e3f07d5@c5c9i0>

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