Post

DP11 Split One Column into Two Fields

Description

This script is designed to split a combined field containing a pattern that is used to separate the information. In this example, the field ‘Practice…NPI’ is compounded. The primary objective is to separate the National Provider Identifier (NPI) from the practice name in each case. The str_split_fixed function from the stringr package is applied for that purpose.

R Script - Split One Column into Two Fields

Initial Data

11 Input Initial Data with the field required to split

Table:

Medicaid.IDPractice…NPI
MID_10000CAPE FEAR VALLEY PRIMARY CARE - FAYETTEVILLE FAMILY: 1548704042-003
MID_10001A BRIGHTER FUTURE HEALTHCARE: 1538491642-003
MID_10002BIRTH AND WOMEN’S CARE: 1124089040-003
MID_10003ALPHA MEDICAL CENTER: 1285719997-003
MID_10004CAROLINA PEDIATRIC GROUP: 1467595959-003
MID_10005CAROLINA PEDIATRIC GROUP: 1467595959-003
MID_10006CAROLINA URGENT AND FAMILY CARE: 1467679712-003
MID_10007BIRTH AND WOMEN’S CARE: 1124089040-003
MID_10008A WOMAN’S PLACE IN FAYETTEVILLE: 1326006438-003
MID_10009CAPE FEAR VALLEY PEDIATRICS: 1295738920-003

Code to split

Split into two fields using the separator “: “

1
stringr::str_split_fixed(PPL_df$Practice...NPI, ": ", n = 2) 

The new dataframe is then appended to the original data frame

Final Result

11 Result Result with only the practice name

__

End of Post

This post is licensed under CC BY 4.0 by the author.