grep - Difficulties adding data to R dataset -
i'm not advanced r appreciated. trying add values columns in dataset , dataset called 'katie'. example, in column 'word' i'd select instances 'subjected' written , post 'middle' in column 'pre.environment', on same line 'subjected' written. there doing wrong? code, initial line works (as can see how many "subjected" items recognized in column 'word') nothing happens when enter second line of code.
>x=grep("subjected", katie$word) >katie[x,]$pre.environment= c('middle')
i hope example sufficient. in advance help.
try following code, if understand question correctly,
katie$pre.environment <- ifelse(grepl("subjected", katie$word), yes = "middle", no = katie$pre.environment)
Comments
Post a Comment