0

I need to answer this question for an assignment "What is the total number of individuals of the tree Poulsenia armata in the 50-hectare plot?". This is for the BCI data in the vegan package This is literally my first R assignment and I honestly don't know what I'm doing lol

I have tried:

tot_ind <- BCI
tot_ind <- grep("Poulsenia.armata", names(tot_ind), value=TRUE)

and

tot_ind <- which(names(tot_ind)=="Poulsenia.armata")

It will say there no data available in table or

Error in FUN(left, right) : non-numeric argument to binary operator

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
ajb0014
  • 25
  • 2
  • `tot_ind` is not a table, `grep(., value = TRUE)` returns character strings with no `names` attribute set. Check what is in it and what `names(tot_ind)` returns. What is it that you are trying to do with `tot_ind`? – Rui Barradas Apr 14 '20 at 05:28
  • If you want to pull out a *column*, like the question title says, try right after the `grep` instruction `BCI[[tot_ind]]` or to pull out a *table* with just one column, `BCI[tot_ind]` . See [Dynamically select data frame columns using $ and a vector of column names](https://stackoverflow.com/questions/18222286/dynamically-select-data-frame-columns-using-and-a-vector-of-column-names) and [Difference between `[` and `[[`](https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el) – Rui Barradas Apr 14 '20 at 05:33
  • The column name is `"Poulsenia.armata"`, you don't need `grep` for that to subset. You can do `sum(tot_ind[, "Poulsenia.armata"])` to get sum of total count in that column. – Ronak Shah Apr 14 '20 at 05:51
  • tot_ind is just something I made up...so far whats in tot_ind is just what's in BCI..50 rows (hectars) and 225 columns (tree species). I just want to pull out the column labeled "Poulsenia.armata" and total the occurrences of this species – ajb0014 Apr 14 '20 at 05:55
  • Thank you Ronak Shah, that worked. Sorry for such a simple question! – ajb0014 Apr 14 '20 at 06:08

1 Answers1

0

In BCI data column name is "Poulsenia.armata". You can directly subset it from the data and use sum to calculate sum of values in it.

sum(tot_ind[, "Poulsenia.armata"])
#[1] 755
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213