? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070323/be84ac14/attachment.pl
Sergio Della Franca wrote:> Dear R-Helpers, > > I have this dataset: > > YEAR PRODUCTS cluster > 1 10 2 > 2 42 3 > 3 25 2 > 4 42 3 > 5 40 3 > 6 45 1 > 7 44 1 > 8 47 1 > 9 42 1 > > > I want to create a subset (when cluster=1), > > YEAR PRODUCTS cluster > 6 45 1 > 7 44 1 > 8 47 1 > 9 42 1 > > > How can i perform this? > >You've answered your own question! ?subset e.g., subset(my.data, cluster==1) You should also notice that many R functions support a subsetparameter, which is very useful! Mark -- Dr. Mark Wardle Specialist registrar, Neurology Cardiff, UK
See ?subset !!! And please do read the psoting guide. Uwe Ligges Sergio Della Franca wrote:> Dear R-Helpers, > > I have this dataset: > > YEAR PRODUCTS cluster > 1 10 2 > 2 42 3 > 3 25 2 > 4 42 3 > 5 40 3 > 6 45 1 > 7 44 1 > 8 47 1 > 9 42 1 > > > I want to create a subset (when cluster=1), > > YEAR PRODUCTS cluster > 6 45 1 > 7 44 1 > 8 47 1 > 9 42 1 > > > How can i perform this? > > > Thank you in advance. > > > Sergio Della Franca > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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.
You want to obtain a subset of your data, so what about to use subset()...?? You didn't even consider doing some basic search for the solution as the posting guide asks you... Petr Sergio Della Franca napsal(a):> Dear R-Helpers, > > I have this dataset: > > YEAR PRODUCTS cluster > 1 10 2 > 2 42 3 > 3 25 2 > 4 42 3 > 5 40 3 > 6 45 1 > 7 44 1 > 8 47 1 > 9 42 1 > > > I want to create a subset (when cluster=1), > > YEAR PRODUCTS cluster > 6 45 1 > 7 44 1 > 8 47 1 > 9 42 1 > > > How can i perform this? > > > Thank you in advance. > > > Sergio Della Franca > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070326/586ce8b7/attachment.pl
Sergio, Please be sure to cc: the list (ie. Reply to All) with follow up questions. In this case, you would use %in% with a negation: NewDF <- subset(DF, (var1 == 0) & (var2 == 0) & (!var3 %in% 2:3)) See ?"%in%" for more information. HTH, Marc On Mon, 2007-03-26 at 17:30 +0200, Sergio Della Franca wrote:> Ok, this run correctly. > > Another question for you: > > I want to put more than one condition for var3, i.e.: > I like to create a subset when: > - var1=0 > - var2=0 > - var3 is different from 2 and from 3. > > Like you suggested, i perform this code: > NewDF <- subset(DF, (var1 == 0) & (var2 == 0) & (var 3 != 2)) & (var > 3 != 3)) > > There is a method to combine (var 3 != 2)) & (var 3 != 3)) in one > condition? > > Thank you. > > Sergio > > > > 2007/3/26, Marc Schwartz <marc_schwartz at comcast.net>: > On Mon, 2007-03-26 at 17:02 +0200, Sergio Della Franca wrote: > > Dear R-Helpers, > > > > I want to make a subset from my data set. > > > > I'd like to perform different condition for subset. > > > > I.e.: > > > > I like to create a subset when: > > - var1=0 > > - var2=0 > > - var3 is different from 2. > > > > How can i develop a subset under this condition? > > > > Thank you in advance. > > > > Sergio Della Franca. > > See ?subset > > Something along the lines of the following should work: > > NewDF <- subset(DF, (var1 == 0) & (var2 == 0) & (var 3 != 0)) > > HTH, > > Marc Schwartz
hi, ok I understand how to use the subset function but sometimes I need to use it to extract data by date and its format it isn't so easy (like below) for example like in using SQL I thougth that it was possible to write "%/2004" but it doesn't run. Can you help me please about this? subset(don, Date_O in "%/2004", select = c(Annee_O, Date_O)) ___________________________________________________________________________ Découvrez une nouvelle façon d'obtenir des réponses à toutes vos questions ! Profitez des connaissances, des opinions et des expériences des internautes sur Yahoo! Questions/Réponses [[alternative HTML version deleted]]