[R-sig-eco] How do I convert a matrix from abundant into presence/absence data?

MARCELINO DE LA CRUZ ROT marcelino.delacruz at upm.es
Wed Feb 13 09:50:16 CET 2013


It works even for a data.frame:


> M=matrix(sample(c(0,1,2,3),25, rep=T),5,5)
> M=data.frame(M)
> M
   X1 X2 X3 X4 X5
1  1  3  3  3  2
2  2  0  1  0  0
3  2  1  0  2  2
4  2  1  3  1  2
5  2  2  3  0  3
> M[M>0] <-1
> M
   X1 X2 X3 X4 X5
1  1  1  1  1  1
2  1  0  1  0  0
3  1  1  0  1  1
4  1  1  1  1  1
5  1  1  1  0  1
>

Cheers,

Marcelino



El 2013-02-12 23:04, Farrar.David at epamail.epa.gov escribió:
> Seems for that approch M should me a matrix (which I bet it actually
> is in this case)
> not a data frame.
>
> I wonder about the following, if you will forgive a slight 
> digression:
> It seems for really large matrices there could be a speedup as well 
> as
> savings of memory with something like.
>
> M <- (M>0) # logical, or
> M <- (M>0)*1L # integer 01
>
> Whether it would make a practical difference would be another thing.
> You can look at sizes of objects with object.size().
> regards,
> David
>
> r-sig-ecology-bounces at r-project.org wrote on 02/12/2013 04:19:09 PM:
>
>  > From: MARCELINO DE LA CRUZ ROT <marcelino.delacruz at upm.es>
>> To: <r-sig-ecology at r-project.org>
>> Date: 02/12/2013 04:20 PM
>> Subject: Re: [R-sig-eco] How do I convert a matrix from abundant
>  > into presence/absence data?
>> Sent by: r-sig-ecology-bounces at r-project.org
>>
>  > Let's say your matrix or data.frame is named M
>  >
>  > M[M>0] <-1
>  >
>  > Now M is only 0's and 1's
>  >
>  > HTH,
>  > Marcelino
>  >
>  >
>  > El 2013-02-12 22:04, Cory Redman escribió:
>  > > I am sure there is any easy solution to this, but due to my
>  > > monkey-level understanding of R, I need some help and can't seem 
> to
>  > > find the answer to my question via the web.
>  > >
>  > > I have been successful in importing an abundance dataset (taxa =
>  > > rows,
>  > > sample sites = columns) into R, but I want to rerun some 
> analyses by
>  > > converting this dataset into presence/absence data, How do I do 
> this?
>  > >
>  > > Cheers,
>  > > Cory
>  > >
>  > > _______________________________________________
>  > > R-sig-ecology mailing list
>  > > R-sig-ecology at r-project.org
>  > > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [1]
>  >
>  > --
>  > MARCELINO DE LA CRUZ ROT
>  > Universidad Politecnica de Madrid
>  >
>  > _______________________________________________
>  > R-sig-ecology mailing list
>  > R-sig-ecology at r-project.org
>  > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [1]
>
>
> Links:
> ------
> [1] https://stat.ethz.ch/mailman/listinfo/r-sig-ecology

-- 
MARCELINO DE LA CRUZ ROT
Universidad Politecnica de Madrid



More information about the R-sig-ecology mailing list