I am trying to run the power.t.test function to calculate sample size for a data frame of variances (i.e, 228 rows x 4 cols). Many of the fields are missing values, which crashes the function. I have tried na. options in the function, but the function doesn't recognize them. I have also tried an if-else loop to skip over fields with missing values. How can I deal with these missing values?
Here's the code: var.df<-read.table("Transect_variance.csv",sep=",",header=TRUE, fill=TRUE) n.df<-data.frame(cbind(var.df[,1:2],rep(-1,228),rep(-1,228),rep(-1,228),rep(-1,228))) names(n.df)<-c("Strata","Transect","n35","n45","n36","n46") #var.df[1:2,] # Strata Transect ID Var35 Var45 Var36 Var46 # Herb 3-1 Herb 3-1 2.024264 NA 7.182 NA # Herb 4-1 Herb 4-1 2.232552 2.26 2.360 2.393387 for i in 1:6 { for j in 1:228 { if ( var.df[i,j]=="") {n.df[i,j]=="" } else { power.t.test(delta = 2.5, sd = var.df[i,j], sig.level = 0.1, power = 0.9, type = "two.sample", alternative = "two.sided") } } } ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.