r - Summing across rows of a data.table for specifc columns -


I have a large data table (with package) with more than 60 columns (according to the first factor and the remaining feedback Variables, different species in this case) and many lines related to treating various levels and species abundance. A very small version looks like this:

  & gt; Library (Data Eligible) & gt; Test & lt; -data.table (time = c ("0", "0", "0", "7", "7", "7", "12"), area = c ("1", "1" "0", "1", "0", "0", "1"), quadrat = c (1,2,3,1,2,3,1), sp1 = c (0,4, 29, 9,1,2,10), SP2 = C (20, 17, 11, 15, 32, 15, 10), SP3 = C (1,0,1,1,1,1,0)) gt ; Setki (test, time) & gt; Exam Time Zone Quad Sp1 SP2 SP3 1: 0 1 1 0 20 1 2: 0 1 2 4 17 0 3: 0 0 3 29 11 1 4: 12 1 1 10 10 0 5: 7 1 1 9 15 1 6: 7 0 2 1 32 1 7: 7 0 3 2 15 1 I want to calculate the mean abundance of each species during the time for each zone X Quadrate combination and it is fine:    & gt; Abundance = Exam [, Lapali (SD, Earth), = "Zone, Quadrate"] by & gt; Abundance Quad Time Sp1 SP2 SP3 1: Z1 1 NA 6.333333 15.0 0.6666667 2: Z1 2 NA 2.5,00,000 24.5 0.50,00,000 3: 1 NA 15.500000 13.0 1.0000000  

But then I want to sum across each row for the 'species' column, for example SP1 to SP3 I did not successfully create the following code Is:

  & gt; Abundance $ SumAbundance & lt; - rowSums (abundance [, c (4: 6)]  

I get error message:
error in rowSums (abundance [, c (4: 6)]): 'X' should have an array of at least two dimensions

This is the first step for a series of calculations to do with this data so that any help would be greatly appreciated. Thanks

"itemprop =" text "> abundance [, c (4: 6)]

actually type See what the outcome is and it will be clear from you that why he was not doing the job. , = RowSums (.sd): This can be corrected with using the = FALSE , but with better syntax (with fewer copies):

  In addition, I did not check, but I suspect it will be fast, because it is the  matrix    Code> rowSums : 

  abundance [SumAbundance: = low (`+`, .SD), .SDcol = 4: 6]  

Comments