Mutate() function works for one set of input files. but throws error when the input file is changed.

Error: Problem with mutate() column. I have installed all the required libraries.

Required Libraries


To be precise, the input file has similar data files with same column name, but the content below the column header varies.
Any help is appreciated.

would you provide any reproduceable examples? otherwise we can't find out what error you encountered exactly.

Hi Thanks for the response,
Not sure what else I can provide, here is the sample snippet of the line I am trying to execute

var1 <- var %>% group_by(abc, Year) %>% summarise(S=sum(S, na.rm = T), L=sum(L, na.rm = T),C=sum(C, na.rm = T),L_C=sum(L_C, na.rm = T),L_D=sum(L_D, na.rm = T)) %>% data.frame() %>% 
+   mutate(Rank1=FUN.Rank_New(L, Type=RankType),
+          Rank1Percentile=FUN.Rank_0_100_New(Loss, Type=RankType),
+          GScore=FUN_Score_1_3(GRnkPercentile)) %>% arrange(GRank) %>% data.frame() 
`summarise()` has grouped output by 'T'. You can override using the `.groups` argument.
Error: Problem with `mutate()` column `GScore`.
i `GScore = FUN_Score_1_3(GRnkPercentile)`.
x invalid 'labels'; length 3 should be 1 or 0
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
Problem with `mutate()` column `GRnkPercentile`.
i `GRnkPercentile = FUN.Rank_0_100_New(L, Type = RankType)`.
i no non-missing arguments to max; returning -Inf 
Called from: signal_abort(cnd)

First, here is a guide you can read about how to provide a minimal reproducible example.

Your error seems to relate to what would appear to be a custom function. (i.e., we can't know what it is, or how it works if you don't provide us that information...) Its returning a result with dimensions that don't fit the data.frame structure expectations. One way to proceed might be to naively capture its results into a list, though this can make for difficult programming. Another way would be to understand the function and to use it (or decide not to use it, but to use something else ) based on its appropriateness for the task.

Thanks @nirgrahamuk and yifanliu alot for your inputs, I will consider them and will try to implement in other ways, Also will try to produce a reproducible code and share it.

I read your code a while, only to find out that the error may be triggered by these self-defined functions, could you provide them?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.