0

I have a dataframe that has 23 columns of various parameters defining a patient which I extracted using dplyr from a larger dataframe after pivoting it such that each of the parameters forms the columns of the new dataframe.

Now I am facing an issue. I am getting a lot of rows for the same patient. For each parameter, one of the rows shows the required value and the rest is denoted as NA. So if the same patient is repeated, say 10 times, in every parameter column there is one row with the actual value and the rest is NA.

How do I remove these NAs and gather the information that is scattered in this manner?

Here is an image showing the issue

I want the 1 and 2 to be on the same row. All the rows seen in this image of dataframe are of the same person.

Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32
  • 1
    Please do not post an image of code/data/errors: it cannot be copied or searched (SEO), it breaks screen-readers, and it may not fit well on some mobile devices. Ref: https://meta.stackoverflow.com/a/285557 (and https://xkcd.com/2116/). Please just include the code, console output, or data (e.g., `dput(head(x))` or `data.frame(...)`) directly. – r2evans Oct 30 '20 at 20:32
  • While it is feasible to try to address that condition in your data, it might be better to fix the errant (or maybe just fragile) process that pivoted into that state. Please make this question a bit more reproducible by providing sample input data (before the pivot), using `dput` or `data.frame`; the code you used to get to this pivoted condition, and your expected output given the sample data you provided. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Oct 30 '20 at 20:34
  • As r2evans suggests it is better to fix the origin of the problem, please go through the links shared above and create a reproducible example which leads you this state so that it is easier to help. – Ronak Shah Oct 31 '20 at 04:11

0 Answers0