search for: squarederror

Displaying 1 result from an estimated 1 matches for "squarederror".

2009 Oct 21
1
How do I vectorize this loop....
...ample=1:6, Live =c(24,25,30,31,22,23), Baseline = c(35,35,35,32,34,33),Zone = c(rep("Cottonwood",3),rep("OregonAsh",3))) Data2 <- data.frame(Zone = c("Cottonwood","OregonAsh"), Survival = c(0.83,0.76)) for (i in 1:nrow(Data1)) #####(Yi -Ybar*Yo)^2 Data1$SquaredError[i] <- (Data1$Live[i] - Data2$Survival[which(Data1$Zone[i]==Data2$Zone)]*Data1$Baseline[i])^2 My question is, can I vectorize this code to avoid the loop? Obviously, I could merge the 2 datasets first, but that would still require 2 steps and Data1 would have a bunch of redundant data. So, is...