Displaying 1 result from an estimated 1 matches for "internatl".
Did you mean:
internal
2011 Dec 11
2
as.factor does not work inside function
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]] <- as.factor(df[[col]])
}
}
}
source('D:/ambertuil.r')
x <- 1:5
y <- 2:6
df <- data.frame(x=x, y=y)