Hi, I have data of two times series & I want to know if they are statistically different. I have like 120 possible combinations and other time series to analyze too, so I have to generate a loop for it.
I would like to :
- Name variables (this works, but bad coding)
- Have the p.value for each observation. (I only put M (Month), but I would normally have January, May, ect)
1 (ok)
Names <- c("Wind","Expected","Real","Loss","CF_B","CF_N","CF_L")
Time <- c("Y","S", "M", "H","HS", "HM")
rm(Name)
Name <- "H"
for(T in Time) {
for (N in Names) {
Name[N[T]] <- paste(T,"_",N, sep="")
}
}
Name <- as.data.frame(Name)
Name <- subset(Name, Name != "H")
Name$P_Value <- Name$Name
#This seems bad coding, but I don't get why I can't just spawn the vector below without setting it.
2. P.value
This works
Y_Wind <- t.test(Y_Hist$Wind,Y_Hor$Wind,na.rm=TRUE)$p.value
Y_Wind
0.44
But this ain't
for(T in Time) {
for (N in Names) {
x <- noquote(paste(T,"_Hist$",N, sep=""))
y <- noquote(paste(T,"Hor$",N, sep=""))
Name$P_Value[Name$Name == paste(T,"",N, sep="")] <- t.test(x,y,na.rm=TRUE)$p.value
}
}
This is the error that I get :
Error in t.test.default(y, x, na.rm = TRUE) :
nombre d'observations 'x' insuffisant
De plus : Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In var(x) : NAs introduits lors de la conversion automatique.
when I print the x's and y's
Print (x) = Y_Hist$Wind
Print (y) = Y_Hor$Wind
So In my mind it's the same thing.
I think my problem is the paste. Furthermore, I do know that a lapply could be better for it, but I ain't got better results. is there better way to paste ? Or to loop (lapply) more efficiently ?
Thank you !!
P.S. I am kind of new.