r - replace asterisks in dataframe with NA's -



r - replace asterisks in dataframe with NA's -

here's dataframe df

i'm trying:

df=data.frame(rbind(c(1,"*","*"),c("*",3,"*")) df2=as.data.frame(sapply(df,sub,pattern="*",replacement="na"))

it doesn't work because of asterisk i'm getting mad trying replace it.

you should set total reproducible example, people more inclined help when create easy em. anywho...

dat <- data.frame(a=c(1,2,'*',3,4), b=c('*',2,3,4,'*')) > dat b 1 1 * 2 2 2 3 * 3 4 3 4 5 4 * > as.data.frame(sapply(dat,sub,pattern='\\*',replacement=na)) b 1 1 <na> 2 2 2 3 <na> 3 4 3 4 5 4 <na>

r

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -