[R] object length

Petr Pikal petr.pikal at precheza.cz
Tue Dec 20 12:02:16 CET 2005


Hi

On 20 Dec 2005 at 2:21, linda.s wrote:

Date sent:      	Tue, 20 Dec 2005 02:21:34 -0800
From:           	"linda.s" <samrobertsmith at gmail.com>
To:             	r-help at stat.math.ethz.ch
Subject:        	[R] object length

> Why I got warning from the following code?
> > assign("x", c(10, 5, 4, 2, 2))
> > y <- c(x, 0, x)
> > y
>  [1] 10  5  4  2  2  0 10  5  4  2  2
> > v <- 2*x + y + 1
> Warning message:
> longer object length
>         is not a multiple of shorter object length in: 2 * x + y
> > v
>  [1] 31 16 13  7  7 21 21 14  9  7 23

Because longer object length is not a multiple of shorter object 
length e.g.

x has length 5 and y has length 11 and they can be recycled during 
computation only fractionally. So the program computes the result but 
warns you about this. If you expected both vactors have same length 
there is time to look more closely to how they look like and how they 
were constructed.

HTH
Petr




> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list