How to eliminate participants from a diary study

I conducted a diary study in which for 5 days, participants had to answer to 2 times.

My criteria was that people had to answer to at least 3 full days out of the 5. So, that from the overall 10 times in which the questionnaire took place, they had to answer to at least 6 times. Everytime they filled in the questionnaire they had to put a personal code, which is why I can see who answered and how many times.

I put like this:

Morning_Afternoon_PT_EN: is the name of the database

respfreq <- calc.nomiss(Morning_Afternoon_PT_EN$day, tolower(Morning_Afternoon_PT_EN$code), data=Morning_Afternoon_PT_EN) print(respfreq) length(respfreq)

length(respfreq) [1] 56

So, I see that "952345172", "chno45", "limf96","liabr14","life74", "fude38" do not meet the requiremente and I want to eliminate them from the overall data base.

I tried to use subset, like:

NewDataFrame<-subset(Morning_Afternoon_PT_EN, respfreq>6)

But, I get the answer:

NewDataFrame<-subset(Morning_Afternoon_PT_EN, respfreq>6)

Error: Must subset rows with a valid subscript vector. i Logical subscripts must match the size of the indexed input. x Input has size 485 but subscript r has size 56.

I understand the error, but idk how to solve it.

Thanks!

Here is a similar use of subset(). I used the names of the vector that stores the counts to eliminate rows from the data.

set.seed(123)
DF <- data.frame(Name=sample(LETTERS[1:3],size = 10,replace = TRUE),
                 Value=rnorm(10))
DF
#>    Name      Value
#> 1     C  1.7150650
#> 2     C  0.4609162
#> 3     C -1.2650612
#> 4     B -0.6868529
#> 5     C -0.4456620
#> 6     B  1.2240818
#> 7     B  0.3598138
#> 8     B  0.4007715
#> 9     C  0.1106827
#> 10    A -0.5558411
Counts <- table(DF$Name) #You would use calc.nomiss here
Counts
#> 
#> A B C 
#> 1 4 5
AtLeast3 <- Counts[Counts>=3]
AtLeast3
#> 
#> B C 
#> 4 5
names(AtLeast3)
#> [1] "B" "C"
DFsubset <- subset(DF,DF$Name %in% names(AtLeast3))
DFsubset #the name A has been eliminated
#>   Name      Value
#> 1    C  1.7150650
#> 2    C  0.4609162
#> 3    C -1.2650612
#> 4    B -0.6868529
#> 5    C -0.4456620
#> 6    B  1.2240818
#> 7    B  0.3598138
#> 8    B  0.4007715
#> 9    C  0.1106827

Created on 2021-12-03 by the reprex package (v2.0.1)

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.