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

From: Vincent Detours <vdetours_at_ulb.ac.be>
Date: Thu 03 Mar 2005 - 04:44:31 EST


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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Mar 03 05:12:13 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:39 EST