So I have a data frame my_df as follows
my_df <- data.frame(c("0600", "0602", "0603"))
Now I need to write ifelse statement which calculates 3 more variables and append it to a new data frame.
I am not able to find out on how to add multiple executable statements in the loop and append the calculated variables to a new data frame.
Below is my code for ifelse statement.
with(my_df, ifelse(my_df$H == "0600",{d$D <- 1+1 & d$c <- "0600"},
ifelse(my_df$H == "0602",{d$D <- 2+1 & d$c <- "0602"},
{ d$D <- 3+1 & d$c <- "0603"}
)))
I am able to append values to new dataframe with only one executable code inside the ifloop i.e if I have only {d$D <- 1+1} it works perfectly but fails when I have multiple statements to execute.
My output data frame should be as shown below,
D C
2 0600
3 0602
4 0603
ifelse()is a function. ... and you are not saving the result of the function. - jogowith(df,...)you do not need to re-call the df to call its variables, i.e.with(df, ifelse(H == ...))... - Sotos