0

I have a data set something like this.

df_A <- tribble(
  ~product_name,   ~id,      
  "xyz.com",         1,  
  "bkrk.de",         4,
)

I want to remove the characters after the dot, so the desired output would be like this:

df_A <- tribble(
  ~product_name,   ~id,      
  "xyz",         1,  
  "bkrk",         4,
)```
datazang
  • 989
  • 1
  • 7
  • 20

2 Answers2

1
df_A = mutate(df_A, product_name = sub('\\..*', '', product_name))
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
1

Another approach:

library(dplyr)
library(stringr)
df_A %>% mutate(product_name = str_remove(product_name, '\\..*'))
# A tibble: 2 x 2
  product_name    id
  <chr>        <dbl>
1 xyz              1
2 bkrk             4
Karthik S
  • 11,348
  • 2
  • 11
  • 25