[R] problems with which

Nicola Spotorno nicola.spotorno at isc.cnrs.fr
Sun Aug 15 16:08:19 CEST 2010


Hi Michael,

Thanks a lot!

Best,

Nicola


Michael Bedward ha scritto:
> Hi Nicola,
>
> Although you have subsetted the data.frame, the factor variable will
> still include the empty level.
>
> For example, the following...
>
> foo <- data.frame(f = factor(c("a", "b", "c", "b", "a")), val = 1:5)
> foo2 <- foo[ foo$f != "a", ]
> foo2
> str(foo2)
>
> Produces this output...
>
>   f val
> 2 b   2
> 3 c   3
> 4 b   4
>
> 'data.frame':	3 obs. of  2 variables:
>  $ f  : Factor w/ 3 levels "a","b","c": 2 3 2
>  $ val: int  2 3 4
>
> You can drop the unused factor level "a" like this...
>
> foo2$f <- foo2$f[, drop=TRUE]
> str(foo2)
>
> 'data.frame':	3 obs. of  2 variables:
>  $ f  : Factor w/ 2 levels "b","c": 1 2 1
>  $ val: int  2 3 4
>
>
> Michael
>
>
> On 15 August 2010 22:03, Nicola Spotorno <nicola.spotorno at isc.cnrs.fr> wrote:
>   
>> Hello,
>> thanks for your replies, but the logic operator is '!='. If I call
>> sentence_trial the dataframe shows no 'an'  datapoints  as I want but I
>> still have problems with 'str' and 'interaction_plot'.
>>
>> Nicola
>>
>>



More information about the R-help mailing list