[R] How to create a numeric data.frame

Patrizio Frederic frederic.patrizio at gmail.com
Mon Jun 13 17:19:39 CEST 2011


On Mon, Jun 13, 2011 at 4:45 PM, Barry Rowlingson
<b.rowlingson at lancaster.ac.uk> wrote:
> On Mon, Jun 13, 2011 at 11:06 AM, Aparna <aparna.sampath26 at gmail.com> wrote:
>> Hi All
>>
>> I am new to R and  I am not sure of how this should be done. I have a matrix of
>> 985x100 values and the class is data.frame.
>
>  You don't have a 'matrix' in the R sense of the word. You seem to
> have a table of numbers which are stored in an object of class
> 'data.frame'.
>

but you could have one:

a <- data.frame(matrix(rnorm(100),10) # get some data
class(a) # check for its class
as.numeric(a) # whoops, won't work

class(as.matrix(a)) # change class, and
as.numeric(as.matrix(a)) # bingo, it works

PF


-- 
+-----------------------------------------------------------------------
| Patrizio Frederic,
| http://www.economia.unimore.it/frederic_patrizio/
+-----------------------------------------------------------------------



More information about the R-help mailing list