ez.replacewhen | R Documentation |
replace a df: eg, when pt_num=1220, let baby_num=3,baby_name='Bennnnnnn'
keep data type whenever possible, var label and value labels are also kept, but notice that value labels might be incomplete because of the insertion of new unlabelled value
ez.replacewhen(df, print2scr = T, ...)
df |
df |
... |
pt_num=1220,baby_num=3,baby_name='Bennnnnnn',the first element is used as condition to pinpoint the row(s) (multiple matched rows allowed), the rest as cols to be replaced. Quotes around col names are optional, 'pt_num'=1220. |
smilar to ez.recode
num->num (if get replaced with another num), numeric->char (if get replaced with a char), char->char, factor->factor (factor internally converted to char then back to factor)
wrapper of df[[col]][theRow] <- newval
df[theRow,col]=newval # this syntax works also, but df[145:146,2,drop=F]=4 says unused arg drop=F
whether the number in pt_num=1220 should be quoted or not, see ez.replace
for comparison logic details. The conclusion is: alawys better to not quote numbers.
returns a new df
ez.replace
df=ez.replacewhen(nicu,pt_num=1220,baby_num=3,baby_name='Ben')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.