object length

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

object length

linda.s
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: object length

Uwe Ligges
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

Read 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: object length

PIKAL Petr
In reply to this post by linda.s
Hi

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

Date sent:       Tue, 20 Dec 2005 02:21:34 -0800
From:           "linda.s" <[hidden email]>
To:             [hidden email]
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




>
> ______________________________________________
> [hidden email] 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
[hidden email]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: object length

Jim Lemon-2
In reply to this post by linda.s
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

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