Hello helpful R folks, First off, please forgive my English. Second, I'm new with R, I've searched the archives about subsets, and I haven't found quite the help I need. I'm currently analysing a population survey whose data set has about 15000 households (the rows/observations) and 130 variables (the columns). I've managed to import the set into R as a data.frame called eu08. Now, I'm trying to look at all of the variables, but limited to one province in the "region" variable. I think the provinces are factors, and the province of interest is labeled '3'. I've tried the following: region3=subset(eu08, region==3) --this simply strips all of the rows from the columns, and I know that about 4000 of the observations are specific to region 3. So does putting the 3 as '3' and "3". Any help would be greatly appreciate. -- View this message in context: http://n4.nabble.com/Subset-Question-tp1568555p1568555.html Sent from the R help mailing list archive at Nabble.com.
Hi r-help-bounces at r-project.org napsal dne 25.02.2010 07:37:44:> > Hello helpful R folks, > > First off, please forgive my English. Second, I'm new with R, I've > searched the archives about subsets, and I haven't found quite the helpI> need. > > I'm currently analysing a population survey whose data set has about15000> households (the rows/observations) and 130 variables (the columns). I've > managed to import the set into R as a data.frame called eu08. Now, I'm > trying to look at all of the variables, but limited to one province inthe> "region" variable. I think the provinces are factors, and the provinceof> interest is labeled '3'. > I've tried the following: > > region3=subset(eu08, region==3)This shall work. What really are values of region? What does str(eu08$region) tell you about it? If it is really factor, what are really its levels? What does level(eu08$region) show? Regards Petr> --this simply strips all of the rows from the columns, and I know thatabout> 4000 of the observations are specific to region 3. So does putting the3 as> '3' and "3". > > Any help would be greatly appreciate. > > -- > View this message in context: http://n4.nabble.com/Subset-Question- > tp1568555p1568555.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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
<<This shall work. What really are values of region? What does str(eu08$region) tell you about it? If it is really factor, what are really its levels? What does level(eu08$region) show?>> My thoughts were also that it would work, but it results in 130 column headings stripped of all rows. To answer your questions: str(eu08$region) yielded: $ region : Factor w/ 10 levels "1.Byrard",..: 3 3 3 3 10 10 10 4 4 4 ... level(eu08$region) yielded nothing, but levels(eu08$region) yielded: [1] "1.Byrard" "2.Alsat" "3.Bigur" [4] "4.Itziar" "5.Ingur" "6.Git" [7] "7.Git Balance" "8.Triage" "9.Snolunt" [10] "10.Bigntu" Thanks for your attention, Petr! -- View this message in context: http://n4.nabble.com/Subset-Question-tp1568555p1568584.html Sent from the R help mailing list archive at Nabble.com.
Hi r-help-bounces at r-project.org napsal dne 25.02.2010 08:22:48:> > <<This shall work. What really are values of region? What does > str(eu08$region) tell you about it? If it is really factor, what are > really its levels? What does level(eu08$region) show?>> > > My thoughts were also that it would work, but it results in 130 column > headings stripped of all rows. > To answer your questions: > str(eu08$region) yielded: > $ region : Factor w/ 10 levels "1.Byrard",..: 3 3 3 3 10 10 10 4 4 4...> > level(eu08$region) yielded nothing, but levels(eu08$region) yielded: > [1] "1.Byrard" "2.Alsat" "3.Bigur" > [4] "4.Itziar" "5.Ingur" "6.Git" > [7] "7.Git Balance" "8.Triage" "9.Snolunt" > [10] "10.Bigntu"Here is your problem. Factor is integer numeric vector with label for each separate level of factor. If you want question your factor you need to use proper label. see subset(eu08, region=="1.Byrard") Regards Petr> > Thanks for your attention, Petr! > -- > View this message in context: http://n4.nabble.com/Subset-Question- > tp1568555p1568584.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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.
Chertudi wrote:> Hello helpful R folks, > > First off, please forgive my English. Second, I'm new with R, I've > searched the archives about subsets, and I haven't found quite the help I > need. > > I'm currently analysing a population survey whose data set has about 15000 > households (the rows/observations) and 130 variables (the columns). I've > managed to import the set into R as a data.frame called eu08. Now, I'm > trying to look at all of the variables, but limited to one province in the > "region" variable. I think the provinces are factors, and the province of > interest is labeled '3'. > I've tried the following: > > region3=subset(eu08, region==3) > --this simply strips all of the rows from the columns, and I know that about > 4000 of the observations are specific to region 3. So does putting the 3 as > '3' and "3". > > Any help would be greatly appreciate. > >Well, we don't know if it really is a factor. You can determine that by doing... class(eu08$region) If it is a factor, then levels(eu08$region) should let you know what you can subset with. str(eu08) might also be good to look at... Erik
Thank you Eric and Petr. It seems to be working now! -- View this message in context: http://n4.nabble.com/Subset-Question-tp1568555p1569461.html Sent from the R help mailing list archive at Nabble.com.
Maybe Matching Threads
- Speed up graphics output?
- Calculating total observations based on combinations of variable values
- shapefiles manipulations ??
- Change state names to abbreviations in an irregular list of names, abbreviations, null values, and foreign provinces
- (no subject)