Re: [R] (no subject)

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Mon, 14 Mar 2011 14:58:35 -0400

On Mar 14, 2011, at 12:25 PM, Andreas Emanuelsson wrote:

> Hi everyone, I have problems with a double for loop and the program
> response: "Error in 1:mass[j] : NA/NaN argument"
>
> I'm trying to create a very simple script to generate a vector full
> of objects with the value [fuel] and in the amount [mass] for a hist
> plot.
>
> H=1
> for (j in 1:63)
> {for (i in 1:mass[j])
>
> { H[length(H)+1]=fuel[j]}
> }
>
> What does the error mean?(where do I find explanations for such
> issues?

You seem to need to read up on basic R programming. That would appear to be an assignment task for which an indexed solution would be much more appropriate. It is really rather bizarre to walk along a vector (as you do for `mass`) without doing anything in the function body with the index.

H <- vector(64, "numeric")
H[2:64] <- fuel[1:63]

>
> Why does not a simple for loop work?
>
> Error in 1:mass[j] : NA/NaN argument

It appears that for some value between 1 and 63, a value for mass[j] is missing. Without a better description of the data (specifically `mass`), not much more can be said.

>
> Thank you very much for your time if you can help me!
>
> /Andreas
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> 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.

David Winsemius, MD
West Hartford, CT



R-help_at_r-project.org mailing list
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. Received on Mon 14 Mar 2011 - 19:03:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Mar 2011 - 19:20:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive