Message-ID: <1352893859.57967.YahooMailNeo@web122406.mail.ne1.yahoo.com>
Date: 2012-11-14T11:50:59Z
From: Fg Nu
Subject: R wildcards, sapply and as.factor
I want to change the type to factor of all variables in a data frame whose names match a certain pattern.
So here I am trying to change the type to factor of all variables whose name begins with?namestub?in the dataframe?df.
attach(df)sapply(grep(glob2rx("namestub*"),names(df)),as.factor)
But this doesn't work since
>levels(df$namestub1)NULL