jon
jon

Reputation: 11366

can I change property of R object

My Ldt1 object has the following property.

> is(Ldt1)
[1] "data.frame" "list"       "oldClass"   "vector"

I want to change it to data.frame only. How can I do it ?

Edits:

I am answering to question of "why?"

I need to work between two packages. The first package works on different class object and second on different class. In the data manipulation process I have trouble with uncessary class type attached with object giving an error message as:

No method for an object of class genotypeNo method for an object of class factor

Upvotes: 0

Views: 545

Answers (1)

IRTFM
IRTFM

Reputation: 263382

You simply cannot. All data.frames are lists and all lists are vectors. (Why would you want to do such a thing anyway?)

Properly written methods will be written to see if the sought-after class is either in the list of the class attribute or in one of its inherited classes. In your case, you (or one of your programs) appear to have made a data input error and turned what you thought should be a numeric vector into a factor vector, or teh designer thought that a factor variable was the logical object to return. It's possible that you could get success by identifying the object or the component and coercing it with 'as.numeric(as.character(facvar))`. (That particular method is a FAQ question.) The better way way forward here is to identify the source of the input or processing error.

Upvotes: 2

Related Questions