我有一个数据集重复更换元件,称为鸣叫,像这样:的R - 在数据帧
V1 V2 V3
1 pos text1 text4
2 neg text2 text1
3 neu text3 text5
在V2有3424个OBS,而在V3 1000个OBS。这些obs是从.txt文件导入的推文。 我想是这样的:
V1 V2 V3
1 pos NA text4
2 neg text2 text1
3 neu text3 text5
所以,如果在V2的元素是相同V3的元素,在V2的元素必须与NA取代。
我tryed使用此代码:
x <- "N/A"
for(i in 1:1000){
for(l in 1:3424){
if(full_corpus[i,3] == (full_corpus[l,2])){
replace(full_corpus,l,x)
}}}
我不知道这是否是做到这一点的最好办法,而我不知道真的很好如何“替换”的作品。
我收到此错误信息:
Error in Ops.factor(full_corpus[i, 3], (full_corpus[l, 2])) :
level sets of factors are different
我怎么能这样做呢? 对不起,我今年在大学开始使用R和一般编码,在这方面我仍然有很多困难。
我也是这个tryed:
library(dplyr)
df %>% mutate(textA = ifelse(textA %in% textB, NA, textA))
但它不工作。我得到
This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information
和R崩溃。我试图重新安装包的dplyr包,但我有相同的结果。
在此先感谢您的帮助。