Re: [R] Converting Data Types

From: Edward Wijaya <ewijaya_at_gmail.com>
Date: Wed, 21 May 2008 11:52:17 +0900

Hi Peter,

Thanks.

as.matrix() does the trick.

On Wed, May 21, 2008 at 11:31 AM, Peter Alspach <PAlspach_at_hortresearch.co.nz> wrote:
> Edward
>
> Are you sure mymatrix is, in fact, a matrix and note a dataframe (which
> is a list)? I get:
>
>> is.matrix(mymatrix)
> [1] FALSE
>> is.data.frame(mymatrix)
> [1] TRUE
>> samples <- mymatrix[1,]
>> llgm <- dgamma(samples, scale=1, shape=2, log = TRUE)
> Error in dgamma(x, shape, scale, log) :
> Non-numeric argument to mathematical function
>
> That is, the same error as you when mymatrix is a dataframe. But
> convert it to a matrix and:
>
>> mymatrix <- as.matrix(mymatrix)
>> is.matrix(mymatrix)

> [1] TRUE
>> is.data.frame(mymatrix)
> [1] FALSE
>> samples <- mymatrix[1,]
>> llgm <- dgamma(samples, scale=1, shape=2, log = TRUE)
>> llgm
> V1 V2 V3 V4 V5 V6
> -99.25657 -84.01700 -237.40735 -201.26922 -170.53122 -159.29770
>
> HTH ....
>
> Peter Alspach
>
>
>> -----Original Message-----
>> From: r-help-bounces_at_r-project.org
>> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Edward Wijaya
>> Sent: Wednesday, 21 May 2008 2:17 p.m.
>> To: r-help_at_r-project.org
>> Subject: [R] Converting Data Types
>>
>> Hi,
>>
>> How can I convert the matrices to list.
>>
>> For example I have this snippet:
>>
>> samples<-mymatrix[1,]
>> print(samples)
>>
>> which prints:
>>
>> V1 V2 V3 V4 V5 V6
>> 1 103.9 88.5 242.9 206.6 175.7 164.4
>>
>>
>> How can I convert the object "samples" such that it prints:
>> [1] 103.9 88.5 242.9 206.6 175.7 164.4
>>
>> The reason I ask this because I can't use the former
>> "samples" object with this function:
>>
>> llgm <- dgamma(samples, scale=1, shape=2, log = TRUE)
>>
>> which gives this error:
>> e 1374Error in dgamma(x, shape, scale, log) :
>> Non-numeric argument to mathematical function
>>
>> Regards,
>> Edward
>>
>> ______________________________________________
>> R-help_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> The contents of this e-mail are privileged and/or confidential to the named
> recipient and are not to be used by any other person and/or organisation.
> If you have received this e-mail in error, please notify the sender and delete
> all material pertaining to this e-mail.
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 21 May 2008 - 02:55:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 21 May 2008 - 08:30:38 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive