Hi,
I am trying to write a function do cast columns of data frame as
factor in a loop, the source is :
as.factor.loop - function(df, cols){
if (!is.null(df) !is.null(cols) length(cols) 0)
{
for(col in cols)
{
df[[col]] -
I am sorry, it is
for(col in c(x,y)){df[[col]] - as.factor(df[[col]])}
is.factor(df[[x]])
TRUE
On Sun, Dec 11, 2011 at 10:06 AM, Xiaobo Gu guxiaobo1...@gmail.com wrote:
Hi,
I am trying to write a function do cast columns of data frame as
factor in a loop, the source is :
as.factor.loop
Hi Xiaobo,
The problem is that your function is not assigning the results to your
data frame---df is an internatl copy made by the function. This is
done to prevent calling functions to have unexpected events such as
overwriting objects in the global environment. Anyway, I think you
can
Hi Josh,
Your suggesstion works, and the following also works:
as.factor.loop - function(df, cols){
if (!is.null(df) !is.null(cols) length(cols) 0)
{
for(col in cols)
{
df[[col]] - as.factor(df[[col]])
}
}
4 matches
Mail list logo