您可以使用
chatr
(字符翻译自
' '
到
_
transform(example, Event = chartr(" ", "_", Event))
Event Type
1 Negative_other_6 1
2 Negative_other_7 2
3 Neutral_self_1 2
4 Negative_other_6 1
5 Neutral_self_1 2
6 Negative_other_7 2
甚至
gsub
代替
“”
到
_
transform(example, Event = gsub(" ", "_", Event))
Event Type
1 Negative_other_6 1
2 Negative_other_7 2
3 Neutral_self_1 2
4 Negative_other_6 1
5 Neutral_self_1 2
6 Negative_other_7 2
使用tidyverse:
library(dplyr)
example %>%
mutate(Event = janitor::make_clean_names(Event))
Event Type
1 negative_other_6 1
2 negative_other_7 2
3 neutral_self_1 2
4 negative_other_6_2 1
5 neutral_self_1_2 2
6 negative_other_7_2 2