-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathredefdead.R
36 lines (27 loc) · 1.36 KB
/
redefdead.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
source("01_import-data.R")
library(stringr)
#We get the data from behaviour in order to redefine survival. In order to do this, we create survival2, a data frame with the insects that survived.
numextract <- function(string){
str_extract(string, "\\-*\\d+\\.*\\d*")
}
behaviour <- beha
ID <- numextract(behaviour$sample)
survival2 <- data.frame(ID, behaviour$exp_round, behaviour$treatment)
names(survival2)[names(survival2) == "ID"] <- "RepID"
names(survival2)[names(survival2) == "behaviour.exp_round"] <- "exp_round"
names(survival2)[names(survival2) == "behaviour.treatment"] <- "treatment"
#Step 2: We observed that we can not corelate the data from behaviour with the one from survival, as the notations changed (we have sample 29 for exp_round 1)
#We find a work around: merge the data with the survival one, but deleting the days in exp and time to pupate, as those can not be corelated. We just keep the number of individuals that survived and the number of individual that were initially in the experience.
survival <- surv
survival[4:5] <- list(NULL)
redefdead <- replicate(213, 1)
survival <- data.frame(survival, redefdead)
i <- 1
j<- 1
for(i in 1:nrow(survival)){
while(survival$treatment[i] == survival2$treatment[j] &&
survival$exp_round[i] == survival2$exp_round[j] && j < nrow(survival2)){
survival$redefdead[i] <- 0
j<- j+1
i <- i+1
}}