I would like to calculate in R: if in my df in column 2 the value is 1 for example and in column 3 the value is 1, then write in a new column 4 "TP".
col1 <- c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4)
col2 <- c(2,5,7,9,1,4,2,1,8,3,4,1,2,5,7,1,5,4,8,1,2,6,4,8,9,1,2,4,3,5,7,2,8,6,1,2)
col3 <- c(1,0,1,1,0,1,0,1,0,1,0,0,1,1,1,1,0,1,1,1,0,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0)
data <- data.frame(col1, col2, col3)
data$col4 <- NA
Like in this df it would look like
col1 <- c(1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4)
col2 <- c(2,5,7,9,1,4,2,1,8,3,4,1,2,5,7,1,5,4,8,1,2,6,4,8,9,1,2,4,3,5,7,2,8,6,1,2)
col3 <- c(1,0,1,1,0,1,0,1,0,1,0,0,1,1,1,1,0,1,1,1,0,0,1,0,1,0,1,0,1,0,1,1,1,0,1,0)
data <- data.frame(col1, col2, col3)
data$col4 <- NA
data[8,4] <- "TP"
data[16,4] <- "TP"
data[20,4] <- "TP"
data[35,4] <- "TP"
Thanks in advance!