pfc_ivan
2009-Jan-25 22:06 UTC
[R] Omitting a desired line from a table [Beginner Question]
I am a beginner using this R software and have a quick question. I added a file into the R called fish.txt using this line. fish<-read.table("fish.txt", head=T, fill=T) The .txt file looks like this. Since it contains like 300000 lines of data I will copy/paste first 5 lines. Year GeoArea SmpNo Month 1970 1 13 7 1971 1 13 10 1972 1 13 8 1973 2 13 10 1974 1 13 11 Now what I want to do is to omit all the lines in the file that arent happening in GeoArea 1, and that arent happening in Month 10. So basically The only lines that I want to keep are the lines that have GeoArea=1 and Month=10 at the same time. So if GeoArea=2 and Month=10 I dont need it. So i just need the lines that have both of those values correct. How do I delete the rest of the lines that I dont need? Thank you everyone. -- View this message in context: http://www.nabble.com/Omitting-a-desired-line-from-a-table--Beginner-Question--tp21657416p21657416.html Sent from the R help mailing list archive at Nabble.com.
Kingsford Jones
2009-Jan-25 22:32 UTC
[R] Omitting a desired line from a table [Beginner Question]
see ?subset Or use indexing, which is covered in section 2.7 of an introduction to R (but note that a data frame has 2 dimensions) hth, Kingsford Jones On Sun, Jan 25, 2009 at 3:06 PM, pfc_ivan <pfc_ivan at hotmail.com> wrote:> > I am a beginner using this R software and have a quick question. > > I added a file into the R called fish.txt using this line. > > fish<-read.table("fish.txt", head=T, fill=T) > > The .txt file looks like this. Since it contains like 300000 lines of data I > will copy/paste first 5 lines. > > Year GeoArea SmpNo Month > 1970 1 13 7 > 1971 1 13 10 > 1972 1 13 8 > 1973 2 13 10 > 1974 1 13 11 > > Now what I want to do is to omit all the lines in the file that arent > happening in GeoArea 1, and that arent happening in Month 10. So basically > The only lines that I want to keep are the lines that have GeoArea=1 and > Month=10 at the same time. So if GeoArea=2 and Month=10 I dont need it. So i > just need the lines that have both of those values correct. How do I delete > the rest of the lines that I dont need? > > Thank you everyone. > > > -- > View this message in context: http://www.nabble.com/Omitting-a-desired-line-from-a-table--Beginner-Question--tp21657416p21657416.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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. >
Jörg Groß
2009-Jan-25 22:33 UTC
[R] Omitting a desired line from a table [Beginner Question]
fish[fish$GeoArea == 1 & fish$Month == 10] Am 25.01.2009 um 23:06 schrieb pfc_ivan:> > I am a beginner using this R software and have a quick question. > > I added a file into the R called fish.txt using this line. > > fish<-read.table("fish.txt", head=T, fill=T) > > The .txt file looks like this. Since it contains like 300000 lines > of data I > will copy/paste first 5 lines. > > Year GeoArea SmpNo Month > 1970 1 13 7 > 1971 1 13 10 > 1972 1 13 8 > 1973 2 13 10 > 1974 1 13 11 > > Now what I want to do is to omit all the lines in the file that arent > happening in GeoArea 1, and that arent happening in Month 10. So > basically > The only lines that I want to keep are the lines that have GeoArea=1 > and > Month=10 at the same time. So if GeoArea=2 and Month=10 I dont need > it. So i > just need the lines that have both of those values correct. How do I > delete > the rest of the lines that I dont need? > > Thank you everyone. > > > -- > View this message in context: http://www.nabble.com/Omitting-a-desired-line-from-a-table--Beginner-Question--tp21657416p21657416.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.
Stephan Kolassa
2009-Jan-25 22:33 UTC
[R] Omitting a desired line from a table [Beginner Question]
Hi, fish.new <- fish[fish$GeoArea==1 & fish$Month==10,] HTH, Stephan pfc_ivan schrieb:> I am a beginner using this R software and have a quick question. > > I added a file into the R called fish.txt using this line. > > fish<-read.table("fish.txt", head=T, fill=T) > > The .txt file looks like this. Since it contains like 300000 lines of data I > will copy/paste first 5 lines. > > Year GeoArea SmpNo Month > 1970 1 13 7 > 1971 1 13 10 > 1972 1 13 8 > 1973 2 13 10 > 1974 1 13 11 > > Now what I want to do is to omit all the lines in the file that arent > happening in GeoArea 1, and that arent happening in Month 10. So basically > The only lines that I want to keep are the lines that have GeoArea=1 and > Month=10 at the same time. So if GeoArea=2 and Month=10 I dont need it. So i > just need the lines that have both of those values correct. How do I delete > the rest of the lines that I dont need? > > Thank you everyone. > >
Jörg Groß
2009-Jan-26 01:24 UTC
[R] Omitting a desired line from a table [Beginner Question]
sorry, there is a comma missing;> fish[fish$GeoArea == 1 & fish$Month == 10, ]Am 25.01.2009 um 23:33 schrieb J?rg Gro?:> > fish[fish$GeoArea == 1 & fish$Month == 10] > > Am 25.01.2009 um 23:06 schrieb pfc_ivan: > >> >> I am a beginner using this R software and have a quick question. >> >> I added a file into the R called fish.txt using this line. >> >> fish<-read.table("fish.txt", head=T, fill=T) >> >> The .txt file looks like this. Since it contains like 300000 lines >> of data I >> will copy/paste first 5 lines. >> >> Year GeoArea SmpNo Month >> 1970 1 13 7 >> 1971 1 13 10 >> 1972 1 13 8 >> 1973 2 13 10 >> 1974 1 13 11 >> >> Now what I want to do is to omit all the lines in the file that arent >> happening in GeoArea 1, and that arent happening in Month 10. So >> basically >> The only lines that I want to keep are the lines that have >> GeoArea=1 and >> Month=10 at the same time. So if GeoArea=2 and Month=10 I dont need >> it. So i >> just need the lines that have both of those values correct. How do >> I delete >> the rest of the lines that I dont need? >> >> Thank you everyone. >> >> >> -- >> View this message in context: http://www.nabble.com/Omitting-a-desired-line-from-a-table--Beginner-Question--tp21657416p21657416.html >> Sent from the R help mailing list archive at Nabble.com. >> >> ______________________________________________ >> R-help at 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 at 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.