Let's say I have this data frame in R:
df<-data.frame(Id=1:4,name=c("a_b[b]","c_c[f]","g_h[a]","m_a[c]"))
> df
Id name
1 1 a_b[a]
2 2 c_c[a]
3 3 g_h[a]
4 4 m_a[a]
I want to remove brackets and everything inside it and get this data frame as output:
Id name new_name
1 1 a_b[a] a_b
2 2 c_c[a] c_c
3 3 g_h[a] g_h
4 4 m_a[a] m_a
I have a large data frame with these brackets but whenever I tried functions from tidyr
or stringr
libraries, it didn't work well because of those brackets.
It might be simple but I couldn't do it. Thanks