• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Subset rows of data that contain a specific string over several columns

Resolved: Subset rows of data that contain a specific string over several columns

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Subset rows of data that contain a specific string over several columns

Question:

I have a very large dataset and I need to subset my dataset to keep only those IDs that contain the word “Paracetamol” across any of the medication columns ex.medication1, medication2, medication3, etc. until medication50.
Please help <3

Best Answer:

In R you can check the entire data frame on equality with the word “paracetamol” which gives you a boolean matrix. Since TRUE == 1 and FALSE == 0, you can calculate rowSums; and obviously you want to subset where they are greater than zero.
If you have NA in your data, use rowSums(., na.rm=TRUE).
Data:

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Getting ‘502 Bad Gateway’ while deploying Springboot app in EKS

24/03/2023

Resolved: Why is NGINX’s $request_uri empty?

24/03/2023

Resolved: How to convert Java bytecode to Webassembly using CheerpJ compiler

24/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.