Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get unique id count across columns in R?

Tags:

r

I have Legal data that looks like this. I'm using RStudio.

> head(gsu[,107:117])
    HtoODay PAOSLDME DUSHD POELRD XCAB WESDF BILOE HYPERDIF IMPSENS      Billing MALLAMP
42        0     <NA>    No     No  <NA>  <NA>  <NA>       No    <NA>  Hourly      NA
61        0     <NA>    Yes    Yes <NA>   Yes  <NA>      Yes    <NA>  Hourly      NA
230       0     <NA>    No     Yes <NA>  <NA>  <NA>      Yes    <NA>  Hourly      NA
235       0     <NA>    No     No  <NA>  <NA>  <NA>      Yes    <NA>  Hourly      NA
302       0     <NA>    No     No  <NA>  <NA>   No        No    <NA>  Hourly      NA
336       3     <NA>    No     No   Yes  <NA>  <NA>       No    <NA> Consult      NA
> 

I want to get a row count of unique Yes occurrences. By which I mean, if Yes occurs in one column, this registers as a count of 1 regardless of the Yes or No value of another column.

For example, Row 61 would count as 1 count of Yes, even though the row contains multiples Yes's across columns, whereas Row 336 would also register in the overall count as 1, given only one instance of Yes.

Essentially, how do I count unique rows of binary instances across columns, without accounting for multiple within-row instances?

like image 881
Jason Matney Avatar asked Dec 20 '22 04:12

Jason Matney


1 Answers

rowSums(df=="Yes", na.rm=TRUE)>=1

gives

#   42    61   230   235   302   336 
#FALSE  TRUE  TRUE  TRUE FALSE  TRUE 
like image 174
ExperimenteR Avatar answered Jan 05 '23 07:01

ExperimenteR