Hi, I'm very new to R, and I have a question.
I want to add a column to my Data Frame, similar to the 'Count_type_parts' column.
that the values in that column be the sum of the 1 of each type of part.
example:
part 1: 5
part 2: 3
part 3: 4
and already added in the data frame, it looks like the "Count_type_parts" column.
These are the sample data:
library(dplyr)
#---------------------DATA---------------------#---------------------DATA---------------------#---------------------DATA---------------------
parts <- c('Part 1','Part 2','Part 1','Part 1','Part 3','Part 3','Part 1','Part 1','Part 3','Part 3','Part 2','Part 3','Part 3','Part 2','Part 4')
number_of_parts <- c(1,1,1,1,0,1,0,1,1,0,0,0,0,1,0)
date <- as.Date(c('2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14','2010-11-1','2008-3-25','2007-3-14'))
data <- data.frame(parts,number_of_parts,date)
dAta2 <- data%>%
group_by(parts)%>%
summarise(Count_type_parts = n())
data <- merge(data,dAta2, by.x = 'parts',by.y = 'parts')
#---------------------DATA---------------------#---------------------DATA---------------------#---------------------DATA---------------------
I would appreciate your help thank you very much.