I am extremely new to learning coding so please be patient with me.
I have a list made up of two data frames and I need to add a value into a new column col3 based on another column col1. I apologize if it’s something obvious, but I just started a week ago.
t <- c(130, 128, 116, 124, 133, 134, 118, 126, 114, 127, 141, 138, 128, 140, 137, 131, 120, 128, 139, 135)
p <- c(114, 98, 113, 99, 107, 116, 113, 111, 119, 117, 101, 119, 130, 122, 106, 106, 124, 102, 117, 113)
tp_df <- data.frame(t, p)
b <- c( 138, 135, 147, 117, 152, 134, 114, 121, 131, 130)
a <- c( 105, 136, 123, 130, 134, 143, 135, 139, 120, 124)
ba_df <- data.frame(b, a)
bp <- list(tp_df, ba_df)
So far, I’ve managed to get to this point, but the resulting column is populated completely with TRUE instead of based on the value of column 1.
tp_df$Status <- character(20)
ba_df$P.status <- character(10)
bp
for (i in 1:length(bp)){
if (bp$tp_df$p[i] <= 120) {
bp$tp_df$Status[i] <- "FALSE"
} else if(bp$tp_df$p[i] > 120){
bp$tp_df$Status[i] <- "TRUE"
}
}
bp
What I want is this
p t Status
1 130 114 FALSE
2 128 98 TRUE
3 116 113 TRUE
What I have is this
p t Status
1 130 114 FALSE
2 128 98 FALSE
3 116 113 FALSE
New contributor
Lazzie is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.