0

I write to ask for help on this:

enter image description here

I have a dataframe with 3 variables and I want to add the value taking into account the sequence and the product, it can be using the aggregate function and it is as follows.r

enter image description here

    UNICOS <- aggregate(Secuencia ~ Producto, Atencion, function(x), 
    length(unique(x)) UNICOS <- UNICOS[order(-UNICOS$Secuencia), ] 
    UNICOS$Producto <- factor(UNICOS$Producto, levels=UNICOS$Producto, ordered = TRUE)

I have this code but as you can see this one takes into account 2 variables, it tells me the unique values ​​according to the sequence, I need you to add the prices of the same sequence and with the same name

thank you

camille
  • 16,432
  • 18
  • 38
  • 60
  • 1
    Hi, your code seems incomplete / missing some brackets. Your question is precise, but in order for us to understand and solve it, it is necessary that you provide some sample data. There are several ways to provide data, probably adding the output of `dput()` or `dput(head())` to your question is sufficient. Avoid adding code or alphanumeric output as images. Consider how to make a good example: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and see how you can change your question accordingly. – heck1 Sep 05 '19 at 13:16

1 Answers1

0

Using 'dplyr' library can make it more simpler:

library(dplyr)
df <- as.data.frame(read.table("your_input.txt",sep="\t",header=TRUE))
df %>% group_by(producto) %>% summarize(Valor=mean(Valor,na.rm=TRUE))
kashiff007
  • 376
  • 2
  • 12