Full join issue?

I want to check which object in which month no student in 12 months range. There 2 objects and each with 12 months in data set model (there are more than 30 objects and all in 12 months range in real). I want to insert rows to dataset area2021 (13273 rows), so each object has 12 months for each class and school. If a month exists, it means class having student; if a month is not there – means no student and insert from the model dataset. For example, in area2021 dataset, class_id 20981, obj_id Art-03, month 7,8,9,10 and 12 exist, after full join, I want to see the missing month 1,2,3,4,5,6,11 is added. Such should happen for every object in every class and every school. I thought that full join should do it because there are 12 months for objects in one dataset, but...Is there memory issue? How to archive this? Thanks a lots in advance!

model <-data.frame(
stringsAsFactors = FALSE,
year = c(2021,2021,2021,2021,2021,
2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,
2021,2021,2021,2021,2021,2021,2021,2021,2021),
month = c(1,2,3,4,5,6,7,8,9,10,
11,12,1,2,3,4,5,6,7,8,9,10,11,12),
obj_cd = c("Math-01","Math-01","Math-01",
"Math-01","Math-01","Math-01","Math-01","Math-01",
"Math-01","Math-01","Math-01","Math-01","Art-03",
"Art-03","Art-03","Art-03","Art-03","Art-03",
"Art-03","Art-03","Art-03","Art-03","Art-03",
"Art-03")
)
model$flag <- 'Y'

area2021 <- data.frame(
stringsAsFactors = FALSE,
school_id = c("10100","10100","10100",
"10100","10100","10100","10100","10100","10100","10100",
"10100","10100","10100","10100","10100","10100",
"10100","10100"),
class_id = c("20981","20981","20981",
"20981","20981","35642","35642","35642","35642","35642",
"35642","35642","35642","35642","45748","45748",
"45748","45748"),
obj_cd = c("Art-03","Art-03","Art-03",
"Art-03","Art-03","Math-01","Math-01","Math-01",
"Math-01","Math-01","Math-01","Math-01","Math-01",
"Math-01","Art-03","Art-03","Art-03","Art-03"),
year = c(2021,2021,2021,2021,2021,
2021,2021,2021,2021,2021,2021,2021,2021,2021,2021,
2021,2021,2021),
month = c(7,8,9,10,12,4,5,6,7,8,
9,10,11,12,4,5,7,8),
student_cnt = c(20,60,60,80,50,10,10,10,10,
71,23,8,10,
20,10,20,4,8)
)

full <- full_join(area2021,model,by=c('obj_cd','year','month')) %>%
arrange(school_id,class_id,obj_cd,month,year)

They're added to the table but as NA values. What are you hoping to see?

You are right - this is not as what I thought. They 're added in the table, but not added under school, class, object group. Any thoughts? Thank you.

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.