I have a Blood pressure Dataframe with the below data.
Name Age M.F Blood.Pressure
1 A 40 M 110
2 B 55 F 112
3 C 51 M 144
4 D 14 M 134
5 E 48 M 90
6 F 78 M 85
7 G 21 F 135
8 H 59 M 150
9 I 32 F 98
.....
I need to check B.P. of each record and based on the values, I have to create a new column with the strings ("Low","Normal","High") corresponding to B.P. I am using the below code to do that.
excel <- read.csv("SampleCSVFile.csv", header=T)
df1 <- data.frame(excel)
df1
for(i in length(df2$Blood.Pressure))
{
if (df1$Blood.Pressure > 80 & df1$Blood.Pressure < 120)
{
df1$is.cond <- c("Low")
}
else if(df1$Blood.Pressure > 120 & df1$Blood.Pressure < 140)
{
df1$is.cond <- c("Normal")
}
else if(df1$Blood.Pressure > 140)
{
df1$is.cond <- c("High")
}
}
df1
But this is the output that I am getting.
Name Age M.F Blood.Pressure is.cond
1 A 40 M 110 Low
2 B 55 F 112 Low
3 C 51 M 144 Low
4 D 14 M 134 Low
5 E 48 M 90 Low
6 F 78 M 85 Low
7 G 21 F 135 Low
8 H 59 M 150 Low
9 I 32 F 98 Low
10 J 63 M 150 Low
It is not checking each row, it just checks the first Blood pressure value, and based on that it assigns the string to all the rows. can you please help ?