How can I fix this error without using for loop
this is my code
carr_samp <- read_csv("C:/Users/acer/OneDrive/Desktop/New folder (14)/samm.csv")
a <- c(2.938026, 3.456584)
a1=a[1]/4
a2=a[2]/4
b <- c(1/0.8273983, 1/0.4934418)
b1=b[1]^(1/4)
b2=b[2]^(1/4)
if (DF$Number_of_Claims==1)
{
a1=a1
a2=a2
b1=b1
b2=b2
}
if (DF$Number_of_Claims==2)
{
a1=a1+a1
a2=a2+a2
b1=b1+b1
b2=b2+b2
}
if (DF$Number_of_Claims==3)
{
a1=a1+a1+a1
a2=a2+a2+a2
b1=b1+b1+b1
b2=b2+b2+b2
}
if (DF$Number_of_Claims==4)
{
a1=a1+a1+a1+a1
a2=a2+a2+a2+a2
b1=b1+b1+b1+b1
b2=b2+b2+b2+b2
}
I got these messages:
Warning message:
In if (DF$Number_of_Claims == 1) { :
the condition has length > 1 and only the first element will be used
Warning message:
In if (DF$Number_of_Claims == 2) { :
the condition has length > 1 and only the first element will be used
Warning message:
In if (DF$Number_of_Claims == 3) { :
the condition has length > 1 and only the first element will be used
Warning message:
In if (DF$Number_of_Claims == 4) { :
the condition has length > 1 and only the first element will be used
The object DF is not defined in your code. What is it?
Assuming that DF is a data frame, DF$Number_of_Claims is a vector, so DF$Number_of_Claims == 2 may return two or more values. If DF$Number_of_Claims == 2 returns (TRUE, FALSE, TRUE) how do you want the calculation to proceed?
the (DF$Number_of_Claims) is a column containing 96 values (It is not ordered from smallest to largest, but rather randomly) consisting of values from 1 to 4. I want if the DF$Number_of_Claims==1 then take a1,a2,b1and b2 as I show in my code but if DF$Number_of_Claims==2 then take the a1,a2,b1and b2...etc.
But I don't know how to do that.