1

I have dataframe 2 columns with ID and Text. Text has to be split by fullstop and mapped with to same ID.

Ex

|ID. |Text  |
|112 |india is highly populated. Delhi is capital of india 
|113  |Tiger is wild animal.lt lives in forest
| 114 | sky is high

answer should be

|ID  | Text |
| 112| india is highly populated|
|112 |Delhi is capital of India |
|113 | Tiger is wild animal |
|113 |  It lives in forest |
| 114| sky is high

Can you please let me know how to get in R. Thanks in advance

SHP
  • 43
  • 5

1 Answers1

1

We can use separate_rows

library(tidyr)
separate_rows(df1, 'Text', sep="\\.\\s*")

-output

# A tibble: 4 x 2
#     ID Text                     
#  <dbl> <chr>                    
#1   112 india is highly populated
#2   112 Delhi is capital of india
#3   113 Tiger is wild animal     
#4   113 lt livess in forest      

data

df1 <- structure(list(ID = c(112, 113), Text = c("india is highly populated. Delhi is capital of india", 
"Tiger is wild animal.lt livess in forest")), class = "data.frame", row.names = c(NA, 
-2L))
akrun
  • 874,273
  • 37
  • 540
  • 662