2
データフレームがあります。特定の列については、最後のアンダースコアの後ろのすべてを削除します。列の最後のアンダースコアの後ろのすべてを削除します。
ので:
test <- data.frame(label=c('test_test_test', 'test_tom_cat', 'tset_eat_food', 'tisk - tisk'),
stuff=c('blah', 'blag', 'gah', 'nah') ,
numbers=c(1,2,3, 4))
は、私が持っている
result <- data.frame(label=c('test_test', 'test_tom', 'tset_eat', 'tisk - tisk'),
stuff=c('blah', 'blag', 'gah', 'nah') ,
numbers=c(1,2,3, 4))
になる必要があります。
require(dplyr)
test %>%
mutate(label = gsub('_.*','',label))
それは最初のアンダースコアからすべてを落とし、
wrong_result <- data.frame(label=c('test', 'test', 'tset', 'tisk - tisk'),
stuff=c('blah', 'blag', 'gah', 'nah') ,
numbers=c(1,2,3, 4))
0123私に与えます
'テスト%>%に変異(ラベル= GSUB( '_ [し^ _ ] * $ '、' '、label)) ' – alistaire