I have a text file in the following basic format which repeats a few thousand times:
Patient Name- John Smith
Number of dx codes: 123
Number of pr codes: 678
Charges: 910
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Duis arcu ipsum, ultrices placerat mattis ac, venenatis eu magna.
Donec interdum iaculis lacus. Nunc in placerat augue.
In ut odio et dui aliquam sagittis at id augue.
Patient Name- Jane Smith
Number of dx codes: 234
Number of pr codes: 567
Charges: 1011
How can I best get the above text into the following format
Patient Name DxCodes PrCodes Charges
John Smith 123 678 910
Jane Smith 234 567 1011
I have been able to use str_extract from the stringi package to extract all the Patient Names into one dataframe and DxCodes, PrCodes, and Charges into another dataframe as such:
Names
John Smith
Jane Smith
And
Number of dx codes: 123
Number of pr codes: 678
Charges: 910
Number of dx codes: 234
Number of pr codes: 567
Charges: 1011
But am unsure about how to proceed to get the above two dataframes into the desired format? Should I be using a different approach from the start? Would definitely appreciate any help. Thank you!