load('xyz')
a <-colSums(xyz)[1]
I know this would sum the entire column but how can I limit the number of cells (rows) it can sum up?
load('xyz')
a <-colSums(xyz)[1]
I know this would sum the entire column but how can I limit the number of cells (rows) it can sum up?
 
    
     
    
    Not sure whether its what you are looking for
x<-matrix(rnorm(20),4,5)
sum(x[1:2,2])
this would take the sum from row 1 and 2 in the second column
you can adress to the rows and colums with those brackets x[row,col]
 
    
    Since there is no data, here is one approach with package dplyr for selecting a range of rows, based on values of particular column:
sampleData <- data.frame(int = seq(1, 16, by=2),#sequence of numbers from 1 to 16 increment by 2.
                       LETTER = LETTERS[1:8],#the 8 upper-case letters of the english alphabet.
                       month = month.abb[1:8], #the three-letter abbreviations for the first 8 English months
                       Sample = sample(10:20, 8, replace = TRUE),#8 random numbers with replacement from 10 to 20.
                       letter = letters[19:26],#the last 8 lower-case letters of the english alphabet.
                       randomNum = rnorm(8)#
                       ); sampleData;
#>   int LETTER month Sample letter  randomNum
#> 1   1      A   Jan     16      s  0.1254669
#> 2   3      B   Feb     11      t -0.2154908
#> 3   5      C   Mar     11      u -0.3709340
#> 4   7      D   Apr     19      v -0.5496505
#> 5   9      E   May     11      w  0.2783666
#> 6  11      F   Jun     14      x -0.4791717
#> 7  13      G   Jul     12      y  1.5229436
#> 8  15      H   Aug     10      z  0.2406836
library(dplyr);
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
sampleData %>% filter(int > 7 & int <14)
#>   int LETTER month Sample letter  randomNum
#> 1   9      E   May     11      w  0.2783666
#> 2  11      F   Jun     14      x -0.4791717
#> 3  13      G   Jul     12      y  1.5229436
Created on 2020-04-18 by the reprex package (v0.3.0)
