Post

DP13 Match Replace Pattern ReGex

Description

This script is designed to address instances where imported data is presented in a modified format, including date values accompanied by unnecessary time components such as the default 12:00 time. The script employs regular expressions to efficiently eliminate these unnecessary time values, resulting in a refined dataset with only the essential date information. Through the application of regular expressions, the script extracts and retains the date component while discarding the superfluous time details.

R Script - Match Replace Pattern ReGex

Initial data Date + Time

13 Initial Date + Time Initial data: Date + Time

Code with Regular expression. Take the characters before the first space

1
gsub('([0-9]+) .*', '\\1', df$Int_Date)

Final result: Only date

13 Result Final results: Only date

__

End of Post

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