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

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -