[R-sig-Geo] Selecting a range of longitude and latitudes

Ben Tupper btupper @end|ng |rom b|ge|ow@org
Fri Apr 19 03:26:27 CEST 2019


Hi,

The example you give is different than the one listed in the error message.  In your example you bind two 14-element vectors into a matrix of two columns.

cbind(103:116, 3:16)

But in the error you show the first vector is only 8 elements long...

cbind(103:110, 3:16)

When R encounters an attempt to bind columns of unequal length it will try to "recycle" the shorter vector as long as it is a multiple of the longer. In this case of binding an 8-element vector and a 14-element vector it fails.  

Note that shortening up the first vector to 7 does work since 7 is a multiple of 14...

cbind(103:109, 3:16)
      [,1] [,2]
 [1,]  103    3
 [2,]  104    4
 [3,]  105    5
 [4,]  106    6
 [5,]  107    7
 [6,]  108    8
 [7,]  109    9
 [8,]  103   10
 [9,]  104   11
[10,]  105   12
[11,]  106   13
[12,]  107   14
[13,]  108   15
[14,]  109   16


Note how the sequence 103...109 appears twice in the first column.  Recycling is nice (and handy) until you get surprised by it.

Cheers,
Ben

> On Apr 18, 2019, at 8:37 PM, rain1290--- via R-sig-Geo <r-sig-geo using r-project.org> wrote:
> 
> Hi there,
> I am trying to specify a range of longitudes and latitudes. I tried this using the following:
> 
> 
> lonlat <- cbind(103:116, 3:16)  #This would specify a range of longitudes and latitudes
> 
> However, I receive the following warning message:
> Warning message:
> In cbind(103:110, 3:16) :
>  number of rows of result is not a multiple of vector length (arg 1)
> 
> When I specify the longitude and latitude of a specific location, though, it works just fine, like this:
> lonlat <- cbind(103, 3)
> 
> Am I specifying the ranges of coordinates incorrectly? The warning message would suggest yes, but I do not understand why.
> Thanks, and any help with this would be greatly appreciated!
> ~Trav.~
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org

Ecological Forecasting: https://eco.bigelow.org/






	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list