[R] Remove empty levels in subset

Sarah Goslee sarah.goslee at gmail.com
Tue Jun 26 17:31:33 CEST 2012


Hi,

On Tue, Jun 26, 2012 at 8:06 AM, svo <s.vanommen at uu.nl> wrote:
> Hi,
>
> I have exactly the same question (how to remove empty levels in my subset),
> but in my case the factor command does not work, because my dataframe is not
> atomic
>
>> Try this:
>>
>> test2$a <- factor(test2$a)
>>
>
> R gives me the error message:
>
> Error in sort.list(y) : 'x' must be atomic for 'sort.list'
> Have you called 'sort' on a list?
>
> Do you have advice?

I have two pieces of advice.

1. Don't try to use factor() on your entire data frame, but only on a
single column at a time, as shown in the example you included.

2. Provide an example of your data using something like
dput(head(mydata, 10)) so we can offer actual working code.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list