[R-sig-Geo] Using the ENFA from adehabitatHS in R with sp classes
Mathieu Basille
basille.web at ase-research.org
Wed Aug 14 22:01:13 CEST 2013
Sorry I didn't spot that one before... Please try:
join<- cbind(bio1, bio2, bio3, bio4, bio5, bio6, bio7)
and check the class and data:
summary(join)
You want this to be of class SpatialGridDataFrame (or
SpatialPixelsDataFrame), so you want to keep the spatial attributes
together with the data that comes with it.
Also note that, given a Spatial*DataFrame, 'xx at data' is equivalent to
'slot(xx, "data")'.
Hope this helps,
Mathieu.
Le 08/14/2013 03:37 PM, AGG18 at pitt.edu a écrit :
> Dear Mathieu,
>
> Thank you for the assistance.
>
> Upon executing the situation where I take the material of 'join' to
> replace 'map' I receive an error:
>
>> join<- cbind(bio1 at data, bio2 at data, bio3 at data, bio4 at data, bio5 at data,
> bio6 at data, bio7 at data)
>> tab <- slot(join, "data")
> Error in slot(join, "data") :
> no slot of name "data" for this object of class "data.frame"
>
> the description of what is compiled in the maps contain in 'join' are:
>
>> head(join)
> bio1.asc bio2.asc bio3.asc bio4.asc bio5.asc bio6.asc bio7.asc
> 1 NA NA NA NA NA NA NA
> 2 NA NA NA NA NA NA NA
> 3 NA NA NA NA NA NA NA
> 4 NA NA NA NA NA NA NA
> 5 NA NA NA NA NA NA NA
> 6 NA NA NA NA NA NA NA
>> class(join)
> [1] "data.frame"
>
>
> Do I need to create a slot or name an element 'data?'
>
> Please advise further.
>
> Cheers,
> Alannie
>
>> Dear Alannie,
>>
>> Obviously all these "data"s are confusing :)
>> The 'enfa' example uses a dataset call 'lynxjura' (not 'data'), which is a
>> list with several elements. One of these elements is the maps, with the
>> name 'map' (singular!). This is what you want to achieve. This is simply a
>> SpatialPixelsDataFrame, but as far as I can tell, a SpatialGridDataFrame
>> will do too (if you want to know more about the differences between these
>> two, check the sp vignette).
>>
>> So, following your example, just replace "map" by "join", and it should
>> work. The 'slot(map, "data")' line extracts the data frame storing the
>> data
>> of the map, since the dudi.pca and enfa functions do not directly need the
>> spatial attributes.
>>
>> Hope this helps,
>> Mathieu.
>>
>>
>> Le 08/14/2013 02:23 PM, alannie a écrit :
>>> Hi folks!
>>>
>>> I have been having significant difficulty using the sp classes to
>>> perform
>>> the ENFA in R.
>>> The objective of this posting is to inquire about how to "prepare data
>>> for
>>> the ENFA," which in previous versions of the software package adehabitat
>>> was
>>> carried out via 'data2enfa' and the 'dudi.pca' functions.
>>>
>>> I have been using the code:
>>>
>>> #Add table of coordinate locations
>>>
>>>> locs<-read.table("xybartsiifolia.csv", header=TRUE, sep=",")
>>>
>>> #Convert to class sp
>>>
>>>> xy.sp = SpatialPoints(locs)
>>>
>>> #Import .asc variable maps into R.
>>>
>>>> bio1<-read.asciigrid("bio1.asc", as.image = FALSE, plot.image = FALSE,
>>> colname = basename("bio1.asc"), proj4string = CRS(as.character(NA)))
>>>> bio2<-read.asciigrid("bio2.asc", as.image = FALSE, plot.image = FALSE,
>>> colname = basename("bi
>
--
~$ whoami
Mathieu Basille, PhD
~$ locate --details
University of Florida \\
Fort Lauderdale Research and Education Center
(+1) 954-577-6314
http://ase-research.org/basille
~$ fortune
« Le tout est de tout dire, et je manque de mots
Et je manque de temps, et je manque d'audace. »
-- Paul Éluard
More information about the R-sig-Geo
mailing list