Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.GSO.4.58.0503021801330.12047@maxi>
Date: 2005-03-02T17:44:31Z
From: Vincent Detours
Subject: data.frame, data types, and apply

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