Displaying 1 result from an estimated 1 matches for "datfra".
Did you mean:
datera
2005 Apr 20
4
Assign factor and levels inside function
...to go about it? Is
there something like value(object) or name(object) that I can't find?
#sample dataframe for this example
y <- data.frame(
one=c(1,1,3,3,5,7),
two=c(2,2,6,6,8,8))
> levels(y$one) # check out levels
NULL
# the function I've come up with
fncFact <- function(datfra, datfraNm){
datfra$one <- factor(datfra$one, levels=c(1,3,5,7,9))
assign(datfraNm, datfra, pos=1)
}
>fncFact(y, "y")
> levels(y$one)
[1] "1" "3" "5" "7" "9"
I suppose only for aesthetics and simplicity, I'd like to have only...