Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Ajay Askoolum
Thank you Jorge & Michael.

I was being stupid - its the only explanation!

The line I had been executing was 

mtcars[rownames=="Valiant"] # missing rownames argument

but the line I quoted in my post was 

mtcars[rownames(mtcars) != "Valiant",]  # How could I write the correct line in 
the mailing list and not where it matters i.e in R?

Thank you.

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread R. Michael Weylandt
Hi Ajay,

Like Jorge, I can't seem to reproduce the behavior you are worried about.

mtcars[rownames(mtcars) != "Valiant",]

returns a 31x11 data.frame as expected.

When you say it "fails," what error message / result are you seeing?

Michael


On Fri, Feb 17, 2012 at 3:27 AM, Jorge I Velez  wrote:
> Hi Ajay,
>
> In the first case, you need "==" instead of "=" :
>
> R> mtcars[ rownames(mtcars) == "Valiant", ]
>  mpg cyl disp  hp drat   wt  qsec vs am gear carb
> Valiant 18.1   6  225 105 2.76 3.46 20.22  1  0    3    1
>
> For the second case,
>
> R> mtcars[rownames(mtcars) != "Valiant",]
>
> will do it.
>
> See also ?subset.
>
> HTH,
> Jorge.-
>
>
> On Fri, Feb 17, 2012 at 3:02 AM, Ajay Askoolum <> wrote:
>
>> data(mtcars)
>>
>> mtcars[rownames(mtcars)!="Valiant",] # fails
>>
>> mtcars[list(rownames(mtcars))!="Valiant",] # runs but I am not getting the
>> expected result
>>
>> With the latter statement, I expected all rows except the one where the
>> name is "Valiant".
>>
>> I must have got something simple wrong; what is it?
>>
>> Thanks.
>>
>>        [[alternative HTML version deleted]]
>>
>> __
>> R-help@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.
>>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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.

__
R-help@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.


Re: [R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Jorge I Velez
Hi Ajay,

In the first case, you need "==" instead of "=" :

R> mtcars[ rownames(mtcars) == "Valiant", ]
 mpg cyl disp  hp drat   wt  qsec vs am gear carb
Valiant 18.1   6  225 105 2.76 3.46 20.22  1  031

For the second case,

R> mtcars[rownames(mtcars) != "Valiant",]

will do it.

See also ?subset.

HTH,
Jorge.-


On Fri, Feb 17, 2012 at 3:02 AM, Ajay Askoolum <> wrote:

> data(mtcars)
>
> mtcars[rownames(mtcars)!="Valiant",] # fails
>
> mtcars[list(rownames(mtcars))!="Valiant",] # runs but I am not getting the
> expected result
>
> With the latter statement, I expected all rows except the one where the
> name is "Valiant".
>
> I must have got something simple wrong; what is it?
>
> Thanks.
>
>[[alternative HTML version deleted]]
>
> __
> R-help@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


[R] Dataframe subset - why doesn't this work?

2012-02-17 Thread Ajay Askoolum
data(mtcars)

mtcars[rownames(mtcars)!="Valiant",] # fails

mtcars[list(rownames(mtcars))!="Valiant",] # runs but I am not getting the 
expected result

With the latter statement, I expected all rows except the one where the name is 
"Valiant".

I must have got something simple wrong; what is it?

Thanks.

[[alternative HTML version deleted]]

__
R-help@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.