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 + 1Warning 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
linda.s wrote:> 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 + 1Read the Warning message and try to interpret it!!!! If you still do not get the point: (length(x)*2+1) == length(y) Uwe Ligges> 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 > > ______________________________________________ > 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
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 23Because 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.htmlPetr Pikal petr.pikal at precheza.cz
linda.s wrote:> 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 the y vector contains 11 elements and the x vector contains 5. The message is just to warn the user that the elements of the shorter vector will not be uniformly represented in the result. Jim