Understanding apply function in R -
in r, i've come across utilize of apply function. have looked @ documentation, want create sure understand correctly.
in following, z n*t matrix.
> x <- apply(z, 1, var) this code generates vector of dimension n*1, element in x variance of i'th row of z. correct?
this have been written for-loop. how look?
let's m matrix
the apply function this
for(i in 1:nrow(m)){function(m[i,])}
where function can var (as in example) or function.
if take sec argument 2 instead of 1, apply same work on columns :
for(i in 1:ncol(m)){function(m[,i])}
r
No comments:
Post a Comment