Hello
When running this code
</>
Distinct_NPC <- df1 %>% distinct(NPC)
for (j in 1:nrow(Distinct_NPC))
{
Distinct_PAIS <- df1 %>% filter(NPC==Distinct_NPC[j,]) %>% distinct(PAIS_COD)
for(i in 1:nrow(Distinct_PAIS))
{
A <- df1 %>% filter(NPC==Distinct_NPC[j,] & PAIS_COD==Distinct_PAIS[i,]) %>% group_by(ANO_REF,MES_REF) %>% summarise(VF = sum(VF))
N <- nrow(A)
if(N!=0) {
B <- A$VF
NPC <- Distinct_NPC[j,]
PAIS_COD <- Distinct_PAIS[i,]
NC8 <- ""
MAD <- c(median(B)-2*mad(B), median(B)+2*mad(B))
Lim_Inf <- MAD[1]
Lim_Sup <- MAD[2]
C <- df1 %>% filter(NPC==Distinct_NPC[j,] & PAIS_COD==Distinct_PAIS[i,] & MES_REF==1) %>% group_by(MES_REF) %>% summarise(VF = sum(VF))
D <- nrow(C)
ifelse(D==0, VF <- 0, VF <- C$VF)
Res_2MAD <- if(VF<MAD[1]|VF>MAD[2]) {Res_2MAD <- "outlier"} else{Res_2MAD <- "normal"}
New <- data.frame(NPC, PAIS_COD, NC8, VF, Lim_Inf, Lim_Sup, Res_2MAD, N)
if(j==1 & i==1) {NPC_PAIS_VF <- data.frame(NPC, PAIS_COD, NC8, VF, Lim_Inf, Lim_Sup, Res_2MAD, N)}
else {NPC_PAIS_VF <- rbind.data.frame(NPC_PAIS_VF, New)}
}
}
}
</>
I've obtained this error message:
summarise()
regrouping output by 'ANO_REF' (override with .groups
argument)
Error: Problem with filter()
input ..1
.
x dims [product 1] do not match the length of object [815358]
i Input ..1
is &...
.
Run rlang::last_error()
to see where the error occurred.
rlang::last_error()
<error/dplyr_error>
Problem withfilter()
input..1
.
x dims [product 1] do not match the length of object [815358]
i Input..1
is&...
.
Backtrace:
- dplyr::filter(...)
- dplyr:::h(simpleError(msg, call))
Runrlang::last_trace()
to see the full context.
rlang::last_trace()
<error/dplyr_error>
Problem withfilter()
input..1
.
x dims [product 1] do not match the length of object [815358]
i Input..1
is&...
.
Backtrace:
x
- +-
%>%
(...) - | +-base::withVisible(eval(quote(
_fseq
(_lhs
)), env, env)) - | -base::eval(quote(
_fseq
(_lhs
)), env, env) - | -base::eval(quote(
_fseq
(_lhs
)), env, env) - | -
_fseq
(_lhs
) - | -magrittr::freduce(value,
_function_list
) - | -function_list[i]
- | +-dplyr::filter(...)
- | -dplyr:::filter.data.frame(...)
- | -dplyr:::filter_rows(.data, ...)
- | +-base::withCallingHandlers(...)
- | -mask$eval_all_filter(dots, env_filter)
- -base::.handleSimpleError(...)
- -dplyr:::h(simpleError(msg, call))
Can you help me please?