ez.replacewhen: replace when

View source: R/frame.R

ez.replacewhenR Documentation

replace when

Description

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

Usage

ez.replacewhen(df, print2scr = T, ...)

Arguments

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.

Details

smilar to ez.recodenum->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.

Value

returns a new df

See Also

ez.replace

Examples

df=ez.replacewhen(nicu,pt_num=1220,baby_num=3,baby_name='Ben')

jerryzhujian9/zmisc documentation built on March 9, 2024, 12:49 a.m.