Dear R-list members, Here goes a simple question that I could not solve: I want to delete a row in a data frame. Suppose rows 5 and 9 are out-layers and I want to take them out from a data frame named "length1.dat": LT LF 1 335 320 2 340 335 3 360 355 4 370 365 5 376 310 6 388 378 7 395 385 8 400 390 9 400 410 10 405 392 I tried to make another data frame: length2.dat <- data.frame(subset(length1.dat,select=-[5,])) # to take out the 5th row and also ... select= [-c(5,)] ... [-5,-9] ... many other variations, without success. I?d be thankful to receive any help. I have printed Maindonald?s ?Using R ...? and Verzani?s ?simpleR? but I could not find any hint on this matter. Thanks in advance, Antonio Olinto Fisheries Institute Sao Paulo - BRAZIL -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Antonio, This seems to work (but you may want to adjust the resulting column names): length2.dat <- data.frame(cbind(length1.dat$LT[-c(5,6)], length1.dat$LF[-c(5,6)])) _____________________________________ Paul S.P. Cowpertwait IIMS, Massey University, Albany, Private Bag 102 904 North Shore Mail Centre Auckland, NZ Tel (+64) (9) 443 9799 ext 9488 http://www.massey.ac.nz/~pscowper _____________________________________ -----Original Message----- From: Antonio Olinto [mailto:aolinto at bignet.com.br] Sent: Wednesday, 5 September 2001 10:51 To: R-help Subject: [R] data manipulation Dear R-list members, Here goes a simple question that I could not solve: I want to delete a row in a data frame. Suppose rows 5 and 9 are out-layers and I want to take them out from a data frame named "length1.dat": LT LF 1 335 320 2 340 335 3 360 355 4 370 365 5 376 310 6 388 378 7 395 385 8 400 390 9 400 410 10 405 392 I tried to make another data frame: length2.dat <- data.frame(subset(length1.dat,select=-[5,])) # to take out the 5th row and also ... select= [-c(5,)] ... [-5,-9] ... many other variations, without success. I?d be thankful to receive any help. I have printed Maindonald?s ?Using R ...? and Verzani?s ?simpleR? but I could not find any hint on this matter. Thanks in advance, Antonio Olinto Fisheries Institute Sao Paulo - BRAZIL -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Antonio, it is much simpler than that: length2.dat <- length1.dat[-c(5,9),] You can of course overwrite the existing dataframe if you want: length1.dat <- length1.dat[-c(5,9),] Robert Denham Qld Dept. Natural Resources Brisbane>Dear R-list members,> Here goes a simple question that I could not solve: I want to delete a row > in a data frame. > Suppose rows 5 and 9 are out-layers and I want to take them out from adata> frame named "length1.dat":> LT LF > 1 335 320 > 2 340 335 > 3 360 355 > 4 370 365 > 5 376 310 > 6 388 378 > 7 395 385 > 8 400 390 > 9 400 410 > 10 405 392> Antonio Olinto > Fisheries Institute > Sao Paulo - BRAZIL************************************************************************ The information in this e-mail together with any attachments is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any form of review, disclosure, modification, distribution and/or publication of this e-mail message is prohibited. If you have received this message in error, you are asked to inform the sender as quickly as possible and delete this message and any copies of this message from your computer and/or your computer system network. ************************************************************************ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._