I want to sort my.data[4:10] in descending order by row. Some clues here, but I could not parse it sufficiently: Sort second to fifth column for each row in R.
I al
This seems to work fine:
my.data[,4:10] <- t(apply(my.data[,4:10], 1, function(x) sort(x, na.last = T, decreasing=T)))
# habitat NumSites NumSamples Sp1 Sp2 Sp3 Sp4 Sp5 Sp6 Sp7
#1 Marsh 3 6 3 1 NA NA NA NA NA
#2 Prairie 3 5 2 2 2 NA NA NA NA
#3 Savanna 4 8 67 3 3 1 NA NA NA
#4 Swamp 1 2 2 NA NA NA NA NA NA
#5 Woodland 4 8 2 1 1 1 1 NA NA