Re: [R] How to select given row of conditionally subsetted dataframe?
Hello, If the sub-df has more than 2 rows, tail(df[(df$Y>0.2) & (df$X<10),], 1) Hope this helps, Rui Barradas Às 08:51 de 14/10/21, Luigi Marongiu escreveu: Hello, I have selected a subset of a dataframe with the vector syntax (if this is the name): ``` df[(df$Y>0.2) & (df$X<10),] YX 10 0.2200642 1.591589 13 0.2941828 1.485951 ``` How can I select only the second row? I only managed to get the whole of whole columns: ``` df[(df$Y>0.2) & (df$X<10),2] [1] 1.591589 1.485951 df[(df$Y>0.2) & (df$X<10),][2] X 10 1.591589 13 1.485951 df[(df$Y>0.2) & (df$X<10),][1] Y 10 0.2200642 13 0.2941828 ``` Thank you __ R-help@r-project.org 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. __ R-help@r-project.org 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.
Re: [R] How to select given row of conditionally subsetted dataframe?
Got it, thanks! On Thu, Oct 14, 2021 at 9:59 AM Eric Berger wrote: > > df[(df$Y>0.2) & (df$X<10),][2,] > > On Thu, Oct 14, 2021 at 10:52 AM Luigi Marongiu > wrote: >> >> Hello, >> I have selected a subset of a dataframe with the vector syntax (if >> this is the name): >> ``` >> > df[(df$Y>0.2) & (df$X<10),] >> YX >> 10 0.2200642 1.591589 >> 13 0.2941828 1.485951 >> ``` >> How can I select only the second row? I only managed to get the whole >> of whole columns: >> ``` >> > df[(df$Y>0.2) & (df$X<10),2] >> [1] 1.591589 1.485951 >> > df[(df$Y>0.2) & (df$X<10),][2] >> X >> 10 1.591589 >> 13 1.485951 >> > df[(df$Y>0.2) & (df$X<10),][1] >> Y >> 10 0.2200642 >> 13 0.2941828 >> ``` >> Thank you >> >> __ >> R-help@r-project.org 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. -- Best regards, Luigi __ R-help@r-project.org 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.
Re: [R] How to select given row of conditionally subsetted dataframe?
df[(df$Y>0.2) & (df$X<10),][2,] On Thu, Oct 14, 2021 at 10:52 AM Luigi Marongiu wrote: > Hello, > I have selected a subset of a dataframe with the vector syntax (if > this is the name): > ``` > > df[(df$Y>0.2) & (df$X<10),] > YX > 10 0.2200642 1.591589 > 13 0.2941828 1.485951 > ``` > How can I select only the second row? I only managed to get the whole > of whole columns: > ``` > > df[(df$Y>0.2) & (df$X<10),2] > [1] 1.591589 1.485951 > > df[(df$Y>0.2) & (df$X<10),][2] > X > 10 1.591589 > 13 1.485951 > > df[(df$Y>0.2) & (df$X<10),][1] > Y > 10 0.2200642 > 13 0.2941828 > ``` > Thank you > > __ > R-help@r-project.org 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]] __ R-help@r-project.org 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.
Re: [R] How to select given row of conditionally subsetted dataframe?
You're missing a comma, this should fix it df[(df$Y>0.2) & (df$X<10),][2, ] On Thu, Oct 14, 2021, 03:51 Luigi Marongiu wrote: > Hello, > I have selected a subset of a dataframe with the vector syntax (if > this is the name): > ``` > > df[(df$Y>0.2) & (df$X<10),] > YX > 10 0.2200642 1.591589 > 13 0.2941828 1.485951 > ``` > How can I select only the second row? I only managed to get the whole > of whole columns: > ``` > > df[(df$Y>0.2) & (df$X<10),2] > [1] 1.591589 1.485951 > > df[(df$Y>0.2) & (df$X<10),][2] > X > 10 1.591589 > 13 1.485951 > > df[(df$Y>0.2) & (df$X<10),][1] > Y > 10 0.2200642 > 13 0.2941828 > ``` > Thank you > > __ > R-help@r-project.org 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]] __ R-help@r-project.org 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.
[R] How to select given row of conditionally subsetted dataframe?
Hello, I have selected a subset of a dataframe with the vector syntax (if this is the name): ``` > df[(df$Y>0.2) & (df$X<10),] YX 10 0.2200642 1.591589 13 0.2941828 1.485951 ``` How can I select only the second row? I only managed to get the whole of whole columns: ``` > df[(df$Y>0.2) & (df$X<10),2] [1] 1.591589 1.485951 > df[(df$Y>0.2) & (df$X<10),][2] X 10 1.591589 13 1.485951 > df[(df$Y>0.2) & (df$X<10),][1] Y 10 0.2200642 13 0.2941828 ``` Thank you __ R-help@r-project.org 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.