[R-sig-Geo] Mysterious (to me) behaviour of cbind() on an envelope -- ASDAR ch. 7

D G Rossiter rossiter at itc.nl
Sat Feb 4 02:03:01 CET 2012


Thanks for the suggestion, but that doesn't work. In fact, I believe cbind.fv is what is being dispatched. But your suggestion gave me the clue to try:

> cbind.data.frame(....)

performs as advertised in ASDAR up to a point --  It indeed binds the DATASET= named column onto the data.frame inside Gresults. BUT the class is now reduced to just a dataframe, and all the attributes of the fv and envelope classes are lost.  I tried coercing this up to fv or envelope with as() but of course there is missing information which I can't re-create.

Is the problem perhaps because of a change in the class dispatch? Since the classes are listed in order as envelope, fv, data.set, maybe the dispatch is to the earliest-named one with a cbind method?

so cbind ---> cbind.fv in this case?

On 03 Feb2012, at 16:16, marcelino.delacruz at upm.es wrote:

> Hi,
>
> I  think this is because Gresuts is an fv object in adtition to a
> data.frame. It has its own cbind.fv method.
>
> From the help.page of fv:
>
> Use cbind.fv to combine several "fv" objects. Use bind.fv to glue
> additional columns onto an existing "fv" object.
>
> So you should use instead bind.fv...
>
> Cheers
>
>
> Marcelino
>
>
> Con fecha 3/2/2012, "D G Rossiter" <rossiter at itc.nl> escribió:
>
>> Dear r-sig-geo friends:
>>
>> I am working through ASDAR (Applied Spatial Data Analysis with R) book using the code and datasets on the book's website http://www.asdar-book.org/.
>>
>> In sppa_mod.R (code for Chapter 7) we are trying to bind a new column giving the point-pattern name to an object of class envelope:
>>
>>> Gresults <- rbind(envjap, envred, envcells)
>>> class(Gresults)
>> [1] "envelope"   "fv"         "data.frame"
>>> Gresults <- cbind(Gresults, DATASET=rep(c("JAPANESE", "REDWOOD", "CELLS"), each=length(r)))
>>
>> but somehow the newly-bound column does not get the assigned name 'DATASET', but is assigned the name 'y':
>>
>>> str(Gresults)
>> Classes 'fv' and 'data.frame':  144 obs. of  6 variables:
>> $ r   : num  0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 ...
>> $ obs : num  0 0 0 0.0615 0.0615 ...
>> $ theo: num  0 0.00509 0.02021 0.04491 0.07843 ...
>> $ lo  : num  0 0 0 0 0 ...
>> $ hi  : num  0 0.0625 0.0748 0.1427 0.1933 ...
>> $ y   : Factor w/ 3 levels "CELLS","JAPANESE",..: 2 2 2 2 2 2 2 2 2 2 ...
>> ....
>>
>> somehow the envelope has been removed also. Then when I try to plot according to the following code:
>>
>>> print(xyplot(obs~theo|DATASET , data=Gresults, type="l", ...
>>
>> the classifying category is not found. If I replace DATASET with y the plot is shown as in Fig. 7.3.
>>
>> Clearly the cbind() is somehow not preserving the assigned column name, despite the class being build on data.frame. Where it gets the 'y' from is also seriously mysterious to me.
>>
>> Here's my version info. I started from a clean workspace and only loaded the packages as indicated.
>>
>>> version
>> platform       x86_64-apple-darwin9.8.0
>> arch           x86_64
>> os             darwin9.8.0
>> system         x86_64, darwin9.8.0
>> status
>> major          2
>> minor          14.0
>> year           2011
>> month          10
>> day            31
>> svn rev        57496
>> language       R
>> version.string R version 2.14.0 (2011-10-31)
>>
>> Package:            sp
>> Version:            0.9-94
>> Date:               2011-12-21
>>
>> Package:            spatstat
>> Version:            1.25-2
>> Date:               2012-01-19
>>
>> Thanks for any insight!
>>
>> D. G. Rossiter
>> Senior University Lecturer
>> University of Twente, Faculty ITC
>> Hengelosestraat 99
>> PO Box 217, 7500 AE Enschede, the Netherlands (NL)
>> Phone:  +31-(0)53 4874 499
>> Fax:    +31-(0)53 4874 336
>> mailto:rossiter at itc.nl,  Internet: http://www.itc.nl/personal/rossiter
>>
>>
>>
>>
>> Faculty of Geo-Information Science and Earth Observation (ITC)
>> University of Twente
>> Chamber of Commerce: 501305360000
>>
>> E-mail disclaimer
>> The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the content of this information is strictly prohibited. If you have received this e-mail by mistake, please delete the message and any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in the message content or for damage of any kind that may arise as a result of e-mail transmission.
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Faculty of Geo-Information Science and Earth Observation (ITC)
University of Twente
Chamber of Commerce: 501305360000

E-mail disclaimer
The information in this e-mail, including any attachments, is intended for the addressee only. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or action in relation to the content of this information is strictly prohibited. If you have received this e-mail by mistake, please delete the message and any attachment and inform the sender by return e-mail. ITC accepts no liability for any error or omission in the message content or for damage of any kind that may arise as a result of e-mail transmission.



More information about the R-sig-Geo mailing list