[R-sig-eco] adehabitat conditional MCP creation and export to csv

Mathieu Basille basille at ase-research.org
Thu Jul 1 21:53:21 CEST 2010


Dear Hakim,

The problem comes from Name being a factor. Even if you subset a factor, 
the levels are still stored, so that it gets 0 relocations for some 
individuals. In addition, I'm a little bit perplexed about your 'for' 
loop (especially the if(summary(p$Name)>=5) component).

I would do something like that:

(q <- subset(p, Name %in% names(which(table(Name) >= 5))))
## Check:
table(q$Name)
q$Name <- factor(q$Name)
## Check again:
table(q$Name) # Now correct
(bla <- mcp(q[, c("X", "Y")], q$Name, percent = 95))

Hope this helps.
Mathieu


Abdi, Abdulhakim a écrit :
> Hi everyone,
> 
> I've searched a few R lists for an answer to this dilemma but it's got me stumped. I have a dataset not unlike the Puechabon dataset that's included with the Adehabitat package:
> 
>> data(puechabon)
>> p = puechabon$locs
>> p = p[-c(94:120,53:90,37:50,7:29),]
>> p
>     Name Age Sex      X       Y   Date
> 1  Brock   2   1 699889 3161559 930701
> 2  Brock   2   1 700046 3161541 930703
> 3  Brock   2   1 698840 3161033 930706
> 4  Brock   2   1 699809 3161496 930707
> 5  Brock   2   1 698627 3160941 930708
> 6  Brock   2   1 698719 3160989 930709
> 30 Brock   2   1 699207 3161099 930831
> 31 Calou   2   1 700098 3161648 930703
> 32 Calou   2   1 700310 3161323 930704
> 33 Calou   2   1 699877 3161471 930707
> 34 Calou   2   1 700003 3161360 930708
> 35 Calou   2   1 699820 3161387 930709
> 36 Calou   2   1 699778 3161328 930711
> 52  Chou   3   2 699640 3158702 920802
> 53  Chou   3   2 699689 3158857 920803
> 92  Jean   2   1 699448 3158689 930705
> 93  Jean   2   1 699500 3158684 930706
> 94  Jean   2   1 699409 3158794 930707
> 
> I'm trying to create an MCP for each animal that has 5 or more relocation points (e.g. Brock & Calou) and export each MCP to a CSV file. I've tried the following, but I get an error message:
> 
>> summary(p$Name)>=5
> Brock Calou  Chou  Jean
>  TRUE  TRUE FALSE FALSE
> 
>> for (i in 1:nrow(p)){
> + if(summary(p$Name)>=5){
> + mcp.p = mcp(pxy, pid, percent=95)
> + write.table(mcp.p, sep=",", file=paste(pid,".csv"), col.names=NA)
> + }
> + }
> Error in mcp(pxy, pid, percent = 95) :
>   At least 5 relocations are required to fit an home range
> In addition: Warning message:
> In if (summary(p$Name) >= 5) { :
>   the condition has length > 1 and only the first element will be used
> 
> I'm not an expert in R and would appreciate any help.
> 
> 
> Regards,
> 
> _________________________________
> Hakim Abdi, M.Sc.
> Research Intern
> 
> Conservation GIS/Remote Sensing Lab
> Smithsonian Conservation Biology Institute
> 1500 Remount Road
> Front Royal, VA 22630
> phone: +1 540 635 6578
> mobile: +1 747 224 7006
> fax: +1 540 635 6506 (Attn:GIS Lab)
> email: abdia at si.edu
> http://nationalzoo.si.edu/SCBI/ConservationGIS/
> 
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-sig-ecology mailing list
> R-sig-ecology at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

-- 

~$ whoami
Mathieu Basille, Post-Doc

~$ locate
Laboratoire d'Écologie Comportementale et de Conservation de la Faune
+ Centre d'Étude de la Forêt
Département de Biologie
Université Laval, Québec

~$ info
http://ase-research.org/basille

~$ fortune
``If you can't win by reason, go for volume.''
Calvin, by Bill Watterson.



More information about the R-sig-ecology mailing list