Macintosh; Intel Mac OS X 12_4_0
I have two data sets. One named 'datesponte' and the other 'kanasuta'. In 'datesponte' I have trees representing a bird nesting site. A column of years ($annee) associated to each tree are in 'character format'.
I want to associate these trees to the correct year temperature ($Historique.modélisé) in the data set 'kanasuta'.
Structure of the df 'datesponte':
structure(list(CodeNidif = c("A08B08_200801", "A08E31_201501",
"A09A03_200901", "A12B01_201301", "A12B01_201401", "B12RJ52_201201"
), NumCav = c(1, 2, 1, 1, 1, 1), NbVisites = c(8, 4, 2, 1, 1,
4), DatePonte = structure(c(1212105600, 1431388800, 1242086400,
1368316800, NA, 1336867200), tzone = "UTC", class = c("POSIXct",
"POSIXt")), CI(jours)
= c(1, 1, 2, 2, NA, 1), Succes = c("N",
"P", "NA", "NA", NA, "P"), NbJeunesSucces = c("NA", "2", "NA",
"NA", NA, "3"), annee = c("2008", "2015", "2009", "2013", NA,
"2012")), row.names = c(NA, -6L), class = c("tbl_df", "tbl",
"data.frame"))
Structure of df 'kanasuta':
structure(list(DateTime = c("1950-05-01", "1951-05-01", "1952-05-01",
"1953-05-01", "1954-05-01", "1955-05-01"), Historique.modélisé = c("2,3",
"2,4", "2,5", "2,2", "2,3", "2,1"), Répartition.historique..low. = c("0,4",
"0,4", "0,5", "0,5", "-0,3", "0,2"), Répartition.historique..high. = c("4,3",
"4,8", "4,7", "3,8", "4", "4,7"), RCP.2.6.médiane = c("", "",
"", "", "", ""), RCP.2.6.portée..low. = c("", "", "", "", "",
""), RCP.2.6.portée..high. = c("", "", "", "", "", ""), RCP.4.5.médiane = c("",
"", "", "", "", ""), RCP.4.5.portée..low. = c("", "", "", "",
"", ""), RCP.4.5.portée..high. = c("", "", "", "", "", ""),
RCP.8.5.médiane = c("", "", "", "", "", ""), RCP.8.5.portée..low. = c("",
"", "", "", "", ""), RCP.8.5.portée..high. = c("", "", "",
"", "", ""), year = c("1950", "1951", "1952", "1953", "1954",
"1955")), row.names = c(NA, 6L), class = "data.frame")
I tried running the following code:
essai=numeric(37)
for(i in 1:37) {
essai[i]=kanasuta$Historique.modélisé[kanasuta$year==datesponte$annee[1]]
}
kanasuta$Historique.modélisé[kanasuta$year==datesponte$annee[1]] [1] ""
It doesn't seem to work. I'm a beginner in R, and I could really use someone's help. Thanks!