I have two datasets. A with two columns: col1 with the number of the sampling station and col2 with the date. B with: col1 with the number of the sampling station, col2 with the date, col3 the age of the species that found and col4 with the temperature values
for example
A<- matrix(c(1,"2011-07-15",2,"2011-07-20",3,"2011-07-15",4,"2011-07-18"),ncol=2,byrow=TRUE)
B<-matrix(c(1,"2011-07-12",3, 21, 2,"2011-07-12",4, 20,2,"2011-07-12",2, 20,3,"2011-07-15",10, 21,3,"2011-07-13",8, 22,3,"2011-07-12",7, 19,4,"2011-07-12",9, 19,4,"2011-07-10",7, 21,5,"2011-07-20",8, 21),ncol=4,byrow=TRUE)
I want that in table A with a forloop for each row the effective temperature values of tab B are taken if the age is less than 5 days and if the age is greater than or equal to 5 days the temperature is averaged for that station.
I thought that I could do a forlloop and an ifelse, in the meantime I created a column of NA for the temparatura in table A. But I'm stuck on how to write the code. Can you help me? Thank you
for(i in 1:nrow(A)){
ifelse(B$day<5, , )
}
Aucun commentaire:
Enregistrer un commentaire