[Solved] Could you please help me to understand an R code?

First of all, in general, var <- expr evaluates the R expression expr and assigns the result to the variable var. If the statement occurs inside a function, then var becomes a function-local variable, otherwise, it becomes a global variable. c(0,0,0,1,0,1,0,1,1,1,1,0) Combines 12 double literals into a double vector in the order given. matrix(c(0,0,0,1,0,1,0,1,1,1,1,0),4,3, byrow=T … Read more

[Solved] Take one sample per row at a time, compute mean, loop [closed]

First lets make so data to experiment with set.seed(100) example <- matrix(runif(47*30), nrow = 47) example[sample(length(example), 250)] <- NA Now we can calculate our means. The apply function samples a random value from each row (!is.na excludes NA values), mean gets the mean, and replicate repeats this 10000 times. exmeans <- replicate(10000, mean(apply(example, 1, function(x) … Read more