funsRowColSums: Functions for row and column sums of a matrix

funsRowColSumsR Documentation

Functions for row and column sums of a matrix

Description

Two functions: row.sum and col.sum.

row.sum returns the row sums of a given matrix (in particular a contingency table) as a vector and col.sum returns the column sums of a given matrix as a vector. row.sum is equivalent to rowSums function and col.sum is equivalent to colSums function in the base package.

Usage

row.sum(ct)

col.sum(ct)

Arguments

ct

A matrix, in particular a contingency table

Value

row.sum returns the row sums of ct as a vector col.sum returns the column sums of ct as a vector

Author(s)

Elvan Ceyhan

See Also

rowSums and colSums

Examples

n<-20  #or try sample(1:20,1)
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:2,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ct<-nnct(ipd,cls)

row.sum(ct)
rowSums(ct)

col.sum(ct)
colSums(ct)

#cls as a factor
na<-floor(n/2); nb<-n-na
fcls<-rep(c("a","b"),c(na,nb))
ct<-nnct(ipd,fcls)

row.sum(ct)
rowSums(ct)

col.sum(ct)
colSums(ct)

#############
n<-40
Y<-matrix(runif(3*n),ncol=3)
ipd<-ipd.mat(Y)
cls<-sample(1:4,n,replace = TRUE)  #or try cls<-rep(1:2,c(10,10))
ct<-nnct(ipd,cls)

row.sum(ct)
rowSums(ct)

col.sum(ct)
colSums(ct)


nnspat documentation built on May 29, 2024, 10:03 a.m.