Problem context: data frame has structure as follows. The issue is I need a new column, e.g., status_rank, which is not a data.frame of 2 variables. Then need to update the status_rank with values based on another variable for a conditional.
[typo: ifelse is what I used]
Tried conditional with target.market_b/_g ("Bad", "Good" values). 'status' has these plus more that shall be ignored (not == target.market_b/_g).
ifelse(status %in% target.marker_b, "Bad",
ifelse(status %in% target_g, "Good", "N/A")
df$status : chr df$status_rank : 'data.frame' of 2 variables .. $status chr "..." .. $status_rank chr "Bad" "Good" "N/A"
I used a dplyr mutate to create a new field and now I know it mutates the column 'status_rank'. I see now that dplyr mutate is not the correct solution.
df$status_rank <- df %>%
select(status, status_rank) %>%
mutate(status_rank = ifelse(status %in% target.marker_b, "Bad",
ifelse(status %in% target_g, "Good", "N/A")))
Issued new column creation with
df["status_rank"] <- "N/A"
Then mutate operated on 'status_rank' and mutated it into 2 observations. Need a better way to create a new column and apply ifelse(status %in% target.marker_b, "Bad", ifelse(status %in% target_g, "Good", "N/A"). Looking for suggestions.
Data: dput(df$status)
"Current", "Fully Paid", "Current", "Fully Paid", "Charged Off", "Current", "Current", "Fully Paid", "Current", "Fully Paid", "Charged Off", "Late (31-120 days)", "Current", "Fully Paid", "Current", "Fully Paid", "Charged Off", "Current", "Current", "Fully Paid", "Late (31-120 days)", "Fully Paid", "Charged Off", "Current"
elseif
doesn't exist, though you canifelse(cond1, yes1, ifelse(cond2, yes2, no))
. (2) Sample data would be good, as otherwise we're just stabbing in the dark. - r2evanstarget.marker_b
andtarget_g
? - r2evans