Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

wrangling a presents/absents table to long form in r

$
0
0

I an new to R (and think I always be). I am trying to wrangle the table resulting this code (only a very short example):

PlotA<-c(0,1,0,1,0,1,0,1,0,1)
PlotB<-c(0,0,1,1,0,0,1,1,0,0)
PlotC<-c(0,0,0,0,1,1,1,1,0,0)
PlotD<-c(0,0,0,0,0,0,0,0,1,1)

DF<-as.data.frame(cbind(PlotA,PlotB,PlotC,PlotD))
row.names(DF)<-paste0("Species",LETTERS[seq( from = 1, to = 10 )])

To this one (an example of only two plots out of the four):

SpeciesRepeat<-c("SpecisB","SpecisD","SpecisF","SpecisH","SpecisJ","SpecisC","SpecisD","SpecisG","SpecisH")
PlotRepeat<-c(rep("PlotA",length(PlotA [PlotA==1])), rep("PlotB",length(PlotB [PlotB==1])))
DesierdResDF<-cbind(SpeciesRepeat,PlotRepeat)

where every observation of a species in in a plot is represented in a row (obs). tidyverse and basic R code will both be appreciated

Thanks, Idan


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>