[R] two apparent anomalies

analyst41 at hotmail.com analyst41 at hotmail.com
Sat Jan 22 15:16:43 CET 2011


(1)

> a = c("a","b")
> mode(a)
[1] "character"
> b = c(1,2)
> mode(b)
[1] "numeric"
> c = data.frame(a,b)
> mode(c$a)
[1] "numeric"

(2)


> a = c("a","a","b","b","c")
> levels(as.factor(a))
[1] "a" "b" "c"
> levels(as.factor(a[1:3]))
[1] "a" "b"
> a = as.factor(a)
> levels(a)
[1] "a" "b" "c"
> levels(a[1:3])
[1] "a" "b" "c"

Any explanation would be helpful.  Thanks.



More information about the R-help mailing list