dplyr case_when throws error names' attribute [1] must be the same length as the vector [0]
I believe you need to correct TRUE ~ open
to TRUE ~ open_flag
:
ERROR:
d %>%
mutate(
open_flag = case_when(
open_flag == 0 & (click_flag > 0 | mirror_flag > 0) ~ 1,
TRUE ~ open
)
)
Error in `mutate()`:
! Problem while computing `open_flag = case_when(...)`.
Caused by error in `` names(message) <- `*vtmp*` ``:
! 'names' attribute [1] must be the same length as the vector [0]
Run `rlang::last_error()` to see where the error occurred.
CORRECT:
d %>%
mutate(
open_flag = case_when(
open_flag == 0 & (click_flag > 0 | mirror_flag > 0) ~ 1,
TRUE ~ open_flag
)
)
open_flag click_flag mirror_flag
1 0 -1 0
2 2 0 0
3 1 1 3
Input:
d <- data.frame(
open_flag = c(0, 2, 0),
click_flag = c(-1, 0, 1),
mirror_flag = c(0, 0, 3)
)
names' attribute [4000] must be the same length as the vector [5]
setNames
is what you need:
setNames(l, unique(df$ID))
Output:
$A
[1] 1
$B
[1] 2
$C
[1] 3
$D
[1] 4
$E
[1] 5
Related Topics
R Markdown Math Equation Alignment
Rjava Is Not Picking Up the Correct Java Version
Change Paper Size and Orientation in an Rmarkdown PDF
Plotting Survival Curves in R with Ggplot2
The Art of R Programming:Where Else Could I Find the Information
R: Serialize Objects to Text File and Back Again
Labelling Logarithmic Scale Display in R
How to Escape Characters in Variable Names
Dealing with Readlines() Function in R
Why Is the Class of a Vector the Class of the Elements of the Vector and Not Vector Itself
Custom Fill Color in Ggvis (And Other Options)
Ggplot: Manual Color Assignment for Single Variable Only
Find the Index of the Column in Data Frame That Contains the String as Value
Ellipse Containing Percentage of Given Points in R
Clustered Standard Errors in R Using Plm (With Fixed Effects)
How to Replace Outliers with the 5Th and 95Th Percentile Values in R