Is it possible to allow for two different options in column rename (regex)?

I want to rename the column names of a dataframe that I have.

As an example, here are two of the column names:

Ep|Weight|Day1Hour4|FALSE
Ep|Weight|Day1Hour12|FALSE

I want to add _placebo at the end of the timepoint, that is:

Ep|Weight|Day1Hour4_placebo|FALSE
Ep|Weight|Day1Hour12_placebo|FALSE

I’ve been using:
Capture

But of couse this creates this variable naming:

Ep|Weight|Day1Hour4_placebo|FALSE
Ep|Weight|Day1Hour1_placebo2|FALSE

and if I use (.+)Hour([0-9]{2})(.+), then the other one is not renamed.

I tried doing something like this:

(.+)Hour([0-9]|[0-9]{2})(.+)

But it didn’t work.

Of course I could rowsplit the data and execute two different column rename regex and then join, but I have a LOT of columns to rename, and this would take a lot of time.

So I would love to know if there’s a way of renaming them all at the same time, with just one regex command (or other option).

Hi @RoyBatty296 - should be as simple as this -

(.*Hour\d+)(.*)

then the replacement

$1_placebo$2

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.