Help about extracting data

classic Classic list List threaded Threaded
2 messages Options
Aya
Reply | Threaded
Open this post in threaded view
|

Help about extracting data

Aya
Hello,
I'm analyzing a 6-question questionnaire. I need to exclude participants
who answered more than 4 questions with a grade of 3 or higher.
How do I write such a code?
Thank you!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Help about extracting data

glsnow
There are more than one way to do it, and it would help if you
provided some sample data.

But here is an example for one way to do it:

examp.dat <- as.data.frame(matrix(sample(1:5, 100*6, replace=TRUE), ncol=6)
tmp.count <- apply(examp.dat, 1, function(x) sum(x>=3))
examp2.dat <- examp.dat[tmp.count <= 4, ]

examp.dat is a data frame with example data.
tmp.count is then the result of applying an anonymous function to each
row, the function counts how many entries in each row are greater than
or equal to 3
examp2.dat is then created as the subset where tmp.count is less than
or equal to 4.


On Wed, Jun 10, 2020 at 12:47 PM Aya Gilad <[hidden email]> wrote:

>
> Hello,
> I'm analyzing a 6-question questionnaire. I need to exclude participants
> who answered more than 4 questions with a grade of 3 or higher.
> How do I write such a code?
> Thank you!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Gregory (Greg) L. Snow Ph.D.
[hidden email]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.