loops - Looping statistic Tests in R -
i apply t test in r within loop
groups length size diet place 2.4048381 0.7474989 1.6573392 334.3273456 2.72500485 0.86392165 1.8610832 452.5593152 1.396782867 0.533330367 0.8634525 225.5998728 b 1.3888505 0.46478175 0.92406875 189.9576476 b 1.38594795 0.60068945 0.7852585 298.3744962 b 2.53491245 0.95608005 1.5788324 303.9052525
i tried code loop, not working:
for (i in 2:4){ t.test(table[,c(i)] ~ table$groups, conf.level = 0.95) }
can me this? thanks!
your code computes 4 t-tests, results lost, because don't them. try following:
info <- read.table(header=true, text="groups length size diet place 2.4048381 0.7474989 1.6573392 334.3273456 2.72500485 0.86392165 1.8610832 452.5593152 1.396782867 0.533330367 0.8634525 225.5998728 b 1.3888505 0.46478175 0.92406875 189.9576476 b 1.38594795 0.60068945 0.7852585 298.3744962 b 2.53491245 0.95608005 1.5788324 303.9052525") results <- list() (i in 2:4){ results[[i]] <- t.test(info[,i] ~ info$groups, conf.level = 0.95) } print(results)
when interacting repl/console, typing t.test
function compute results , return them. console print returned. in scripts source
, t.test
function return results wil not printed. why put them list , printed list later on.
btw, stored information info
not table
. r deal great variable names function names, every , hava hard time read error messages, avoid naming variables table
or matrix
or c
or df
.
Comments
Post a Comment