[R] Help about extracting data
Greg Snow
538280 @end|ng |rom gm@||@com
Thu Jun 11 01:16:40 CEST 2020
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 <ayagilad using gmail.com> 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]]
>
> ______________________________________________
> R-help using r-project.org 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.
538280 using gmail.com
More information about the R-help
mailing list