Skip to content

data.frame, data types, and apply

2 messages · Vincent Detours, Uwe Ligges

#
Dear all,

Here is an issue I often stumble on.

1- colunm types in data.frames.

-------------------------------
x y
1 a 1
2 b 2
3 c 3
[1] TRUE
[1] FALSE
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
#
Vincent Detours wrote:

            
It is correct!
d is a data.frame, but apply() works on matrices. So d is coerced to a 
matrix which means that there need to be only one mode - and that is 
character!

Check the columns as in

   sapply(d, is.numeric)


Uwe Ligges