R:拆分数据框列中的字符串

R: split a string in a dataframe column

我有一个数据框,其中一列包含字符串。我想拆分那个字符串,用点分隔,并始终保留第一部分。

这将是我的数据框:

                                             State
1             This is my string. I do not want this
2   This is other string. I do not want this either

我想得到这个:

                   State
1      This is my string
2   This is other string

我试过这个,但现在可以用了:

df = df >%> dplyr::mutate(State= str_split(State,".")[1])

这个有用吗:

library(dplyr)
library(stringr)
df
                                            State
1           This is my string. I do not want this
2 This is other string. I do not want this either
df %>% mutate(State = str_remove(State, '\..*'))
                 State
1    This is my string
2 This is other string