Hi,
I am new to R and may be this is a silly question, just wanted to check if multiple loops condition works with vector.
I have a csv file imported as data and I am trying to code something like if column = R then 1 elseif column = A then 2 else column = G then 3 in one column. I can successfully create it in three separate columns but unable to include condition in one.
Below Code:
DataIfElse <- read.csv("C:/Users/vickhzu/Downloads/DataSource_RTest.csv")
DataIfElse$Reporting<-as.Date(DataIfElse$Reporting,"%D/%M/%Y")
x=1
for (val in x) {
DataIfElse$P <- if(DataIfElse$Cost == "R" || DataIfElse$Schedule == "R"|| DataIfElse$Scope == "R") "R" else if(DataIfElse$Cost== "A"|| DataIfElse$Schedule== "A"|| DataIfElse$Scope== "A") "A" else if(DataIfElse$Cost== "G" || DataIfElse$Schedule== "G" || DataIfElse$Scope== "G") "G" else "Z"
x=x+1
}
view(DataIfElse)
This gives me an warning "Warning message: In if (DataIfElse$Cost == "R") { : the condition has length > 1 and only the first element will be used" and only updates first value in the column with desired result. Can anyone please help me resolve the same.
Any help is appreciated. Thanks