Good Morning ??? I have a small question regarding the function subset. I am copying data from one table but I just want to collect data from a user. When do I take the view, presents the results I want. The problem arises when can I make the tab. for RES_ID, introduces me to zero results do not envision noVIEW val_user='16' x.sub <- data.frame(subset(Dataset,Dataset$USER==val_user)) View(x.sub) lev_ID<-levels(x.sub$RES_ID) res<-table(x.sub$RES_ID) res E000- 0 F160- 0 XFRT- 33 XVVR- 0 SWEX- 23 SWRS- 0 just wanted to see the data with values ??greater than 0 in the example only two results because when create the graph create empty space barplot(table(x.sub$RES_ID),width =1,angle=45,inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0,add = FALSE, main="hist C",col=rainbow(x.sub$CALLEDSTATIONID)) Thanks -- View this message in context: http://r.789695.n4.nabble.com/Subset-problem-tp4452837p4452837.html Sent from the R help mailing list archive at Nabble.com.
Hi> > Good Morning > > I have a small question regarding the function subset. > I am copying data from one table but I just want to collect data from a > user. > When do I take the view, presents the results I want. > > The problem arises when can I make the tab. for RES_ID, introduces me to > zero results do not envision noVIEW >You did not provide reproducible example nor structure of you data. From what you explain I think that problem can be in factors behaviour. Factors retain all levels until they are explicitly told to drop them. See ?factor Also your output from table is rather strange. Maybe table(factor(x.sub$RES_ID)) can help you. Without reproducible example it is difficult to evaluate your problem correctly. Regards Petr> > val_user='16' > x.sub <- data.frame(subset(Dataset,Dataset$USER==val_user)) > View(x.sub) > lev_ID<-levels(x.sub$RES_ID) > res<-table(x.sub$RES_ID) > res > E000- 0 > F160- 0 > XFRT- 33 > XVVR- 0 > SWEX- 23 > SWRS- 0 > > just wanted to see the data with values ??greater than 0 in theexample only> two results > > because when create the graph create empty space > barplot(table(x.sub$RES_ID),width =1,angle=45,inside = TRUE, plot =TRUE,> axis.lty = 0, offset = 0,add = FALSE, main="hist > C",col=rainbow(x.sub$CALLEDSTATIONID)) > > Thanks > > > -- > View this message in context: http://r.789695.n4.nabble.com/Subset- > problem-tp4452837p4452837.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.
Thank you. I put table(factor(x.sub$RES_ID)) and works. -- View this message in context: http://r.789695.n4.nabble.com/Subset-problem-tp4452837p4452954.html Sent from the R help mailing list archive at Nabble.com.
I'm having a simple problem with subset. I'm choosing what I think is a valid selection, but I either get everything or an empty dataframe. What am I doing wrong?> > describe(OBDataSumm)Description of OBDataSumm Numeric mean median var sd valid.n SAMPN 2.155e+05 1.733e+05 1.151e+10 1.073e+05 3.378e+04 PATTERN 62.78 35 5285 72.7 3.378e+04 ASSN 8139 8116 3.378e+07 5812 3.378e+04 ~~Clip~~~ ROUTE Value Count Percent MT-802 2297 6.8 MT-801 1552 4.59 MT-804 1159 3.43 MT-803 776 2.3 MT-805 744 2.2 MT-.51 504 1.49 MT-.53 413 1.22 MT-.35 377 1.12 MT-.18 363 1.07 MT-252 361 1.07 mode = MT-802 Valid n = 33782 165 categories - only first 1 ~~Clip~~~> dim(OBDataSumm)[1] 33782 130> SubRed <- subset(OBDataSumm, ROUTE == "MT-802") > dim(SubRed)[1] 0 130>Robert Farley LACMTA 1 Gateway Plaza Los Angeles, CA 90012-2952 (213)922-2532 FarleyR@Metro.net [[alternative HTML version deleted]]
Hi, If my data frame "df" has a index "type", I want to get a subset such that the type belongs to a "type_list"; using sql, I want SELECT name, type FROM df WHERE type in type_list; Now in R I have to write a loop like mysubset<- df [ df$type == type_list[1], ] for (type1 in type_list[ 2: length (type_list) ] ) { mysubset<-cbind (mysubset, df [ df$type == type1, ]) } What is the natural way of doing this in R? Is it possible to use subset() to attain this? Thanks! Best, Reeyarn On Fri, Dec 3, 2010 at 11:26 AM,? William Dunlap?<[hidden email]> wrote:> HI, > I have a dataframe like this: > name ? ?type > A ? ? ? ? ?t1 > B ? ? ? ? ? t2 > C ? ? ? ? ?t1 > D ? ? ? ? ? t4 > E ? ? ? ? ? t3 > F ? ? ? ? ? ?t2 > how can I have a "sub dataframe" based with the column "type" like this: > (for type = t1) > name ? ?type > A ? ? ? ? ?t1 > C ? ? ? ? ?t1 > D ? ? ? ? ? t1Hi, Let's say your data.frame is stored in a variable named "df": R> subset(df, type == 't1') Read the help files: R> ?subset Also take a look at ?split -steve