Extracting rows of a data.frame by "identical"

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extracting rows of a data.frame by "identical"

miao
Is it possible? I am expecting the result to be the second row of the data
frame ...


d<-data.frame(a=1:3, b=3:5,c=9:11)
> d
  a b  c
1 1 3  9
2 2 4 10
3 3 5 11
> d[identical(d[c("b","c")],c(4,10)),]
[1] a b c
<0 rows> (or 0-length row.names)

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting rows of a data.frame by "identical"

Ulrik Stervbo-2
Can you use subset?

subset(d, b == 4 & c == 10)

Best
Ulrik

On Tue, 3 May 2016 04:58 jpm miao, <[hidden email]> wrote:

> Is it possible? I am expecting the result to be the second row of the data
> frame ...
>
>
> d<-data.frame(a=1:3, b=3:5,c=9:11)
> > d
>   a b  c
> 1 1 3  9
> 2 2 4 10
> 3 3 5 11
> > d[identical(d[c("b","c")],c(4,10)),]
> [1] a b c
> <0 rows> (or 0-length row.names)
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Extracting rows of a data.frame by "identical"

Ivan Calandra-4
In reply to this post by miao
I'm not sure what you are trying to do...

Have you checked what the output of d[c("b","c")] is? And what about the
output of identical(d[c("b","c")],c(4,10)) ? As is, I don't see the
point of going through identical(). Maybe you're looking for which() or
"%in%"?

If you just want to subset the second row, and second and third columns,
then just do it! In your code, you forgot to subset for the rows... Here
is an idea:
d[2, c("b","c")]
You can also use the function subset() as Ulrik has shown you.

HTH,
Ivan

--
Ivan Calandra, PhD
Scientific Mediator
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
[hidden email]
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 03/05/2016 à 04:56, jpm miao a écrit :

> Is it possible? I am expecting the result to be the second row of the data
> frame ...
>
>
> d<-data.frame(a=1:3, b=3:5,c=9:11)
>> d
>    a b  c
> 1 1 3  9
> 2 2 4 10
> 3 3 5 11
>> d[identical(d[c("b","c")],c(4,10)),]
> [1] a b c
> <0 rows> (or 0-length row.names)
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.