r - Run Power.t.test for a data frame -


i'm trying run power.t.test on dataframe , trying return samplesize(n) each employee,but it's giving me error.

error in power.t.test(delta = d.f$delta, sd = d.f$sd, sig.level = 0.05, : 1 of 'n', 'delta', 'sd', 'power', , 'sig.level' must null

this i've done far.

dput(d.f) structure(list(power = c(0.95, 0.95, 0.95, 0.95), sig.level = c(0.05,  0.05, 0.05, 0.05), sd = c(4.93255160738102, 20.3907509926899,  23.1325373816684, 6.0463892968789), delta = c(97, 97, 90, 96),      workedby = structure(1:4, .label = c("emp1", "emp2", "emp3",      "emp4"), class = "factor"), newcolumn = c(0, 0, 0, 0)), .names = c("power",  "sig.level", "sd", "delta", "workedby", "newcolumn"), row.names = c(na,  -4l), class = "data.frame") 

first approach

 d.f$newcolumn <- 0  (i in 1:nrow(d.f)) {   n <- power.t.test(delta = d.f$delta, sd = d.f$sd, sig.level=.05, power = .8, type = "one.sample")   d.f$newcolumn[i] <- n } head(d.f) 

second approach:

apply(d.f[,c('power','sig.level','sd','delta')], 1, function(x) power.t.test(x) ) 

can tell me i'm doing wrong. basically, want samplesize returned each employees.

it takes single value input, not data frame. following works:

power.t.test(delta=d.f$delta[1], sig.level=d.f$sig.level[1], power=d.f$power[1], sd=d.f$sd[1]) 

you need wrap in loop , re-assign correct row in "new column".


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -