0

I have created two subsets in my data to group my data however for some reason the subsets are skipping over some qualifying rows and I cant work out why. This is my subset instructions:

W21_24<-subset(kickData,year_week == c("2020-W21","2020-W22","2020-W23","2020-W24"))

W37_41<-subset(kickData,year_week == c("2020-W37","2020-W38","2020-W39","2020-W40","2020-W41"))

which returns correct results into a data frame, however not complete results. It skips over some rows for some reason.

(There are a 116 rows that meet the first subset criteria but it only brings back 28. There are a 144 rows for the second subset but it only brings back 29)

Low
  • 29
  • 4
  • 1
    `year_week == c(...)` is wrong logic. What should `c(1,2,3,4) == c(1,2,3)` be? Realize that R tends to do things as a vector, so that second operation looks like `1==1 & 2==2 & 3==3 & 4==1`, which may seem obscure but is known as "recycling". **Use `year_week %in% c(...)` instead.** – r2evans Dec 08 '20 at 13:56
  • 1
    For future questions, please make them *reproducible* to include a representative sample of your data (as small as possible but big enough to get the point across) using either `data.frame(...)` or the output from `dput(x)` (perhaps `dput(head(x))` for a sample). – r2evans Dec 08 '20 at 13:58
  • Great thanks - i'm a beginner and slowly getting there. much appreciated – Low Dec 08 '20 at 13:58
  • No worries, closing as a dupe can easily be interpreted as "common misunderstand or common mistake" (or some form of "common ..."). And learning how SO prefers questions (with well-structured data, output, etc) is a learning process. Good luck! – r2evans Dec 08 '20 at 14:20

0 Answers0