[R] data.frame, data types, and apply

Vincent Detours vdetours at ulb.ac.be
Wed Mar 2 18:44:31 CET 2005


Dear all,

Here is an issue I often stumble on.

1- colunm types in data.frames.

-------------------------------
> d <- data.frame(x=as.character(c("a", "b", "c")), y=as.numeric(c(1, 2, 3)))
> d
  x y
1 a 1
2 b 2
3 c 3
> is.numeric(d[1,2])
[1] TRUE
> is.numeric(d[1,1])
[1] FALSE
> apply(d, c(1,2), is.numeric)
      x     y
1 FALSE FALSE
2 FALSE FALSE
3 FALSE FALSE
>
-------------------------------

All item in column "y" should be TRUE right? What should I do to apply
a function only to numerics in d? (beside using nested 'for' loops)

Thanks for your help, and for all the great software.


Vincent Detours




More information about the R-help mailing list