Friday, 15 February 2013

data.frame - R - Create presence/absence df -



data.frame - R - Create presence/absence df -

i have data.frame similar following:

species<-c("a","b","c","d") samples<-c(1,2,3,4,5,6) species<-sample(species,20,replace=true) samples=sample(samples,20,replace=true) df <- data.frame(samples,species)

i´d transform in data.frame each species appear column , each sample occupy single line. values (0 , 1) indicate presence , absence. original data.frame has approx. 600k lines, 60k samples , 20 variables (species).

how this:

> reshape2::dcast(df,formula = samples ~ species) samples b c d 1 1 0 0 1 3 2 2 0 3 1 0 3 3 2 1 0 1 4 4 0 1 0 1 5 5 1 1 2 1 6 6 0 0 0 1

r data.frame

2 comments:

  1. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. Antique maps Houston

    ReplyDelete
  2. I just want to let you know that I just check out your site and I find it very interesting and informative.. fotokunst

    ReplyDelete