Skip to content
Prev 2974 / 7420 Next

Presence-absence to Occurrence Dataset?

Hi Elyse,

Tom referred to the mefa package, I'd like to draw the attention to
the mefa4 package which is more efficient and can handle large data
since it uses sparse matrices through the Matrix package. The Melt()
function is the inverse operation to xtabs() or its modified version
Xtabs() in mefa4. It can take a matrix, sparse matrix, S3 mefa or S4
Mefa object as its argument:

library(mefa4)

y <- matrix(sample(0:4, 12, replace=TRUE, prob=c(0.5, rep(0.5/4, 4))), 4, 3)
x <- data.frame(x=runif(4), y=runif(4))
colnames(y) <- LETTERS[1:3]
rownames(y) <- rownames(x) <- paste("row", 1:4, sep="_")

z <- Melt(y)
data.frame(z, x[z$rows,])

There is also the (relatively) new multitable package by Steve Walker
with similar functionality. Lots of ways to do it -- the problem must
bother many of us :)

Cheers,

Peter

P?ter S?lymos
Alberta Biodiversity Monitoring Institute
and Boreal Avian Modelling project
Department of Biological Sciences
CW 405, Biological Sciences Bldg
University of Alberta
Edmonton, Alberta, T6G 2E9, Canada
Phone: 780.492.8534
Fax: 780.492.7635
email <- paste("solymos", "ualberta.ca", sep = "@")
http://www.abmi.ca
http://www.borealbirds.ca
http://sites.google.com/site/psolymos
On Fri, Apr 20, 2012 at 1:06 PM, <Tom_Philippi at nps.gov> wrote: