替換值的字符串值我有了像在查找列表中的R
string<-c('lib1_Rstudio_case1','lib2_Rstudio_case1and2','lib5_python_notthe correct_language','lib3_Jupyter_really_good','lib1_spyder_nice','lib1_R_the_core')
replacement<-c('Rstudio','Jupyter','spyder','R')
我想替換他們更換新的值相匹配的字符串的值id列的數據集。我用下面的代碼現在
gsub(paste(replacement, collapse = "|"), replacement = replacement, x = string)
這另一段代碼裏面我是用找到的情況下
string[grepl(paste(replacement, collapse='|'), string, ignore.case=TRUE)]
我想更新,我覺得 那些我想要的輸出像
Rstudio,Rstudio,'',Jupyter,spyder,R
我不想通過硬編碼它。我想寫一個可擴展的代碼。
任何幫助,非常感謝
在此先感謝
嘗試'ifelse((x < - sub('。* _','',string))%in%replacement,x,'' )' –
這個代碼字對我來說,但我不能替代任何東西 grep(粘貼(替換,崩潰='|',字符串,ignore.case = TRUE)] –
對不起。我將嘗試編輯問題 –