1
Hello, good night!
I have a data frame with thousands of rows and 58 columns containing, for example, supplier, material, quantity of material and total value of material. I made an example below, just what I need at first.
Fornecedor  Material    Qtde    Valor_Total
A   A   1   100
A   B   2   150
A   E   5   26
B   B   6   76
C   A   5   126
C   C   1   58
D   D   10  108
E   E   9   99
E   A   7   30
E   E   8   80
E   E   1   54
F   G   1   0
First, I created a column with the average value of each row
dados$valor_medio <- round(dados$Valor_Total/dados$Qtde,2)
Now I need to calculate the average, median and a new average, apart from the outliers, of dados$valor_medio by material. However, when applying the function tapply the following error occurs:
dados<-tapply(dados$valor_medio, dados$Material, mean, na.rm = TRUE)
Error in tapply($value_medio data, $Material data, Mean, na.rm = TRUE) : arguments must have the same length
Could someone help me with this error and report how I calculate the average taking the outliers of dados$valor_medio of each material?
PS: The material is chr
Probably your column given$Material is a list or something. What is the result of
str(dados$Material)orclass(dados$Material)?– Carlos Cinelli
with this example of yours, I managed to run without any error
– Rafael Cunha
> class(base$Material) [1] "Character"
– Lucimar
In fact, the Material has the following format: 00.000.000. I was unhappy in the example, sorry.
– Lucimar