• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Updating integer within string row for each instance in R dataframe

Resolved: Updating integer within string row for each instance in R dataframe

0
By Isaac Tonny on 16/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Updating integer within string row for each instance in R dataframe

Question:

I have a dataframe similar to the following reproducible one in which one column contains HTML code:
enter image description here
I would like to update the integer within the square brackets of the HTML column to reflect each instance of repeat. For example, the second time that [demography_form] appears in a row, I would like the square brackets following it to be 2:
enter image description here
What’s the best way of going about doing this? I was thinking of somehow creating an instance column and then using that to update the value in the square brackets, deleting it at the end? Thanks in advance.

Best Answer:

Create a grouping column from the substring inside the [] from HTML column, replace the digits inside the [] with the sequence of rows (row_number()) using str_replace_all
-output

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

dataframe dplyr instance r string
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to give rank on datetime column group by another column with userid in it

24/03/2023

Resolved: Passing 2 functions in onChange in react

24/03/2023

Resolved: Why doesn’t stringstream consume output during hex formatting?

24/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.