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

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -