[R] selection part of "subset"

Sarah Goslee sarah.goslee at gmail.com
Thu Jan 5 17:11:40 CET 2012


I don't know how to do it with subset, but this is equivalent for
your example:

tab[tab[[name]] == v,]

Also, you might want to look at ?"==" and ?identical.

Sarah

On Thu, Jan 5, 2012 at 11:04 AM, Christof Kluß <ckluss at email.uni-kiel.de> wrote:
> Hi
>
> the output should look like     r <- subset(tab, a==v)
> but now I have something like   r <- subset(tab, "a"==v)
> and                             r <- subset(tab, [["a"]]==v)
> does not work :(
>
> greetings
> Christof
>
> Am 05-01-2012 16:51, schrieb Christof Kluß:
>> Hi
>>
>> I want to do something like
>>
>> a <- c(10,20,15,43,76,41,25,46)
>> tab <- data.frame(a)
>>
>> name <- "a"
>>
>> for (v in unique(tab[[name]])) {
>>   r <- subset(tab, name==v)   # this does not work
>>   ...
>> }
>>
>> i.e. a "string" on the left side of the select expression (subset). How
>> could I solve this?
>>
>> thx
>> Christof
>>

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



More information about the R-help mailing list