Quantcast
Channel: How can I calculate the number of uniques in a row within a species matrix? - Stack Overflow
Browsing all 5 articles
Browse latest View live

Answer by jay.sf for How can I calculate the number of uniques in a row...

You could first subset for columns with "uniques", lapply comparison greater than zero over remaining columns, finally identify which.> d |> subset(select=colSums(d > 0) == 1) |>...

View Article



Answer by tmfmnk for How can I calculate the number of uniques in a row...

If you want to return only the rows with unique values and the corresponding unique values:ind <- apply(example_data >= 1, 2, which)stack(ind[lengths(ind) == 1]) values ind1 3 Species32 5...

View Article

Answer by Maël for How can I calculate the number of uniques in a row within...

You can use colSums+rowSums like so:cbind(example_data, uniques = rowSums(example_data[colSums(example_data > 0) == 1] > 0))# Species1 Species2 Species3 Species4 Species5 uniques# 1 1 6 0 0 0 0#...

View Article

Answer by jpsmith for How can I calculate the number of uniques in a row...

Since you are interested in which rows have uniques and how many, not which species were uniques:You can find both the row and column indices of those with unique values by first finding which species...

View Article

How can I calculate the number of uniques in a row within a species matrix?

I am trying to identify which rows have uniques (a species that was only observed in that row and not in any other row of my species matrix). I have my data matrix set up with columns as individual...

View Article

Browsing all 5 articles
Browse latest View live


Latest Images

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