Pauline Laïlle
2016-Sep-20 12:42 UTC
[R] "invalid argument to unary operator" while selecting rows by name
Dear all, I built a dataframe with read.csv2(). Initially, row names are integers (order of answers to a survey). They are listed in the csv's first column. The import works well and my dataframe looks like I wanted it to look. Row names go as follows : [1] "6" "29" "31" "32" "52" "55" "63" "71" "72" "80" "88" "89" "91" "93" "105" "110" "111" "117" "119" "120" [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177" "178" "179" "184" "186" "192" "193" "200" "201" "228" etc. I would like to drop rows "601" & "604" to clean the dataframe. While data["601",] shows me the first row i'd like to drop, data[-"601",] returns the following : Error in -"601" : invalid argument to unary operator idem with data[c("601","604"),] and data[-c("601","604"),] It is the first time that I run into this specific error. After reading a bit about it I still don't understand what it means and how to fix it. Thanks for reading! Best, Pauline. [[alternative HTML version deleted]]
Bert Gunter
2016-Sep-20 17:08 UTC
[R] "invalid argument to unary operator" while selecting rows by name
Hint: "601" is not 601. Have you gone through any R tutorials? Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Sep 20, 2016 at 5:42 AM, Pauline La?lle <pauline.laille at gmail.com> wrote:> Dear all, > > I built a dataframe with read.csv2(). Initially, row names are integers > (order of answers to a survey). They are listed in the csv's first column. > The import works well and my dataframe looks like I wanted it to look. > > Row names go as follows : > [1] "6" "29" "31" "32" "52" "55" "63" "71" "72" "80" "88" "89" > "91" "93" "105" "110" "111" "117" "119" "120" > [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177" > "178" "179" "184" "186" "192" "193" "200" "201" "228" > etc. > > I would like to drop rows "601" & "604" to clean the dataframe. > > While data["601",] shows me the first row i'd like to drop, data[-"601",] > returns the following : > Error in -"601" : invalid argument to unary operator > > idem with data[c("601","604"),] and data[-c("601","604"),] > > It is the first time that I run into this specific error. After reading a > bit about it I still don't understand what it means and how to fix it. > > Thanks for reading! > Best, > Pauline. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
ruipbarradas at sapo.pt
2016-Sep-20 17:52 UTC
[R] "invalid argument to unary operator" while selecting rows by name
Hello, Try something like the following. ix <- which(c("601", "604") %in% rownames(data)) clean <- data[-ix, ] Hope this helps, Rui Barradas Citando Pauline La?lle <pauline.laille at gmail.com>:> Dear all, > > I built a dataframe with read.csv2(). Initially, row names are integers > (order of answers to a survey). They are listed in the csv's first column. > The import works well and my dataframe looks like I wanted it to look. > > Row names go as follows : > [1] "6" "29" "31" "32" "52" "55" "63" "71" "72" "80" "88" "89" > "91" "93" "105" "110" "111" "117" "119" "120" > [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177" > "178" "179" "184" "186" "192" "193" "200" "201" "228" > etc. > > I would like to drop rows "601" & "604" to clean the dataframe. > > While data["601",] shows me the first row i'd like to drop, data[-"601",] > returns the following : > Error in -"601" : invalid argument to unary operator > > idem with data[c("601","604"),] and data[-c("601","604"),] > > It is the first time that I run into this specific error. After reading a > bit about it I still don't understand what it means and how to fix it. > > Thanks for reading! > Best, > Pauline. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
ruipbarradas at sapo.pt
2016-Sep-20 18:13 UTC
[R] "invalid argument to unary operator" while selecting rows by name
Sorry, I've made a stupid mistake. It's obviously the other way around. ix <- which(rownames(data) %in% c("601", "604")) clean <- data[-ix, ] Rui Barradas Citando ruipbarradas at sapo.pt:> Hello, > > Try something like the following. > > ix <- which(c("601", "604") %in% rownames(data)) > clean <- data[-ix, ] > > > Hope this helps, > > Rui Barradas > > > > > Citando Pauline La?lle <pauline.laille at gmail.com>: > >> Dear all, >> >> I built a dataframe with read.csv2(). Initially, row names are integers >> (order of answers to a survey). They are listed in the csv's first column. >> The import works well and my dataframe looks like I wanted it to look. >> >> Row names go as follows : >> [1] "6" "29" "31" "32" "52" "55" "63" "71" "72" "80" "88" "89" >> "91" "93" "105" "110" "111" "117" "119" "120" >> [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177" >> "178" "179" "184" "186" "192" "193" "200" "201" "228" >> etc. >> >> I would like to drop rows "601" & "604" to clean the dataframe. >> >> While data["601",] shows me the first row i'd like to drop, data[-"601",] >> returns the following : >> Error in -"601" : invalid argument to unary operator >> >> idem with data[c("601","604"),] and data[-c("601","604"),] >> >> It is the first time that I run into this specific error. After reading a >> bit about it I still don't understand what it means and how to fix it. >> >> Thanks for reading! >> Best, >> Pauline. >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at 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 at 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.
Pauline Laïlle
2016-Sep-21 07:49 UTC
[R] "invalid argument to unary operator" while selecting rows by name
Hi, thanks for the answer. In this case, the row named "601" is not the 601st row of the table, but the 117th. data[601,] actually refers to a non existing row. I was wondering why data[-"601,] generates an error message whereas data["601",] does not? 2016-09-20 19:08 GMT+02:00 Bert Gunter <bgunter.4567 at gmail.com>:> Hint: "601" is not 601. > > Have you gone through any R tutorials? > > Cheers, > Bert > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Tue, Sep 20, 2016 at 5:42 AM, Pauline La?lle > <pauline.laille at gmail.com> wrote: > > Dear all, > > > > I built a dataframe with read.csv2(). Initially, row names are integers > > (order of answers to a survey). They are listed in the csv's first > column. > > The import works well and my dataframe looks like I wanted it to look. > > > > Row names go as follows : > > [1] "6" "29" "31" "32" "52" "55" "63" "71" "72" "80" "88" > "89" > > "91" "93" "105" "110" "111" "117" "119" "120" > > [21] "122" "127" "128" "133" "137" "140" "163" "165" "167" "169" "177" > > "178" "179" "184" "186" "192" "193" "200" "201" "228" > > etc. > > > > I would like to drop rows "601" & "604" to clean the dataframe. > > > > While data["601",] shows me the first row i'd like to drop, data[-"601",] > > returns the following : > > Error in -"601" : invalid argument to unary operator > > > > idem with data[c("601","604"),] and data[-c("601","604"),] > > > > It is the first time that I run into this specific error. After reading a > > bit about it I still don't understand what it means and how to fix it. > > > > Thanks for reading! > > Best, > > Pauline. > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at 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]]