[R-sig-Geo] Selecting a range of longitude and latitudes
r@i@1290 m@iii@g oii @im@com
r@i@1290 m@iii@g oii @im@com
Fri Apr 19 03:51:23 CEST 2019
Hi Ben (and everyone),
Ah, yes, you're right - using the suggestion that you specified, that error message disappeared! So, if I understand, this would take all of the grid cells within those specified longitude and latitude ranges (i.e. that entire area)?
That said, when I try plotting this using the following:
get <- ncvar_get(Model1, "cum_co2_emi-CanESM2") #for x-axis (140 values)
Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var="onedaymax") #for y-axis (140 values)
Hope2 <- extract(Model2, lonlat)
plot(get,Hope2, type="l",col="green", lwd="3", xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation (mm/day)", main="CanESM2")
I receive this error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' and 'y' lengths differ
*Note that I do not have this problem when specifying a "specific" longitude and latitude, rather than a range. Is there any reason for this?
Thanks, again
-----Original Message-----
From: Ben Tupper <btupper using bigelow.org>
To: rain1290 <rain1290 using aim.com>
Cc: r-sig-geo <r-sig-geo using r-project.org>
Sent: Thu, Apr 18, 2019 9:26 pm
Subject: Re: [R-sig-Geo] Selecting a range of longitude and latitudes
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