Hello everybody! I've a file with several data six variables, three quantitative and three qualitative, I would like to select a group of data from the file to analyze then, i.e: my file is like that (but with 6 variables): Var1 Var2 2 1 5 1 8 1 7 2 3 2 8 2 I want to use only the data where var2 is "1" 2 1 5 1 8 1 Exist a way in R to create a new dataframe with a selection of data from other dataframe? _______________________________________________________________________________________________ Michelangelo La Spina Equipo de Protección de cultivos - Control Biológico Departamento de Biotecnología y Protección de Cultivos Instituto Murciano de Investigación y Desarrollo Agrario y Alimentario (IMIDA) C/ Mayor s/n 30150 La Alberca (Murcia) - ESPAÑA teléfono: +34 968 362 788 fax: +34 968 366 792 móvil: +34 618 451 079 web: http://www.imida.es/equipos/eq_prot_cultivos_comp.html e-mail: michelangelo.la@carm.es [[alternative HTML version deleted]]
Try subset. help(subset) Subset returns a subsets of vectors, matrices or data frames which meet conditions. There are some excellent examples in the help. Here is an example similar to your email. Create some data: Var1<-sample(1:10,20,replace=TRUE) Var2<-sample(1:10,20,replace=TRUE) the.old.data<-cbind(Var1,Var2) head(the.old.data) Var1 Var2 [1,] 8 10 [2,] 1 10 the.new.data <- subset(the.old.data, Var2==1) the.new.data HTH, Jeremy On Friday 18 January 2008 10:33:51 LA SPINA, MICHELANGELO wrote:> I've a file with several data six variables, three quantitative and three > qualitative, I would like to select a group of data from the file to > analyze then, i.e: my file is like that (but with 6 variables): > > Var1 Var2 > 2 1 > 5 1 > 8 1 > 7 2 > 3 2 > 8 2 > > I want to use only the data where var2 is "1"-- Jeremy Baxter, Statistics Department, Rhodes University, South Africa. Views expressed above, no matter how badly spelt, are my own... I think?
> I've a file with several data six variables, three quantitative and > three qualitative, I would like to select a group of data from the > file to analyze then, i.e: > my file is like that (but with 6 variables): > > Var1 Var2 > 2 1 > 5 1 > 8 1 > 7 2 > 3 2 > 8 2 > > I want to use only the data where var2 is "1" > 2 1 > 5 1 > 8 1 > > Exist a way in R to create a new dataframe with a selection of data > from other dataframe?#Your data frame df1 <- data.frame(Var1 = c(2,5,8,7,3,8), Var2=rep(1:2, each=3)) #The desired frame df2 <- df1[df1$Var2==1,] #clearer syntax using the subset function df3 <- subset(df1, Var2==1) identical(df2, df3) #TRUE Please read section 2.7 of the 'Introduction to R' manual http://cran.r-project.org/doc/manuals/R-intro.pdf Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
Hi ? subset should do it xx < subset(x, x$Var2==1) --- "LA SPINA, MICHELANGELO" <michelangelo.la at carm.es> wrote:> Hello everybody! > > I've a file with several data six variables, three > quantitative and three qualitative, I would like to > select a group of data from the file to analyze > then, i.e: > my file is like that (but with 6 variables): > > Var1 Var2 > 2 1 > 5 1 > 8 1 > 7 2 > 3 2 > 8 2 > > I want to use only the data where var2 is "1" > 2 1 > 5 1 > 8 1 > > Exist a way in R to create a new dataframe with a > selection of data from other dataframe? >_______________________________________________________________________________________________> > > Michelangelo La Spina > > Equipo de Protecci?n de cultivos - Control Biol?gico > > Departamento de Biotecnolog?a y Protecci?n de > Cultivos > Instituto Murciano de Investigaci?n y Desarrollo > Agrario y Alimentario (IMIDA) > C/ Mayor s/n > 30150 La Alberca (Murcia) - ESPA?A > > tel?fono: +34 968 362 788 > fax: +34 968 366 792 > m?vil: +34 618 451 079 > > web: >http://www.imida.es/equipos/eq_prot_cultivos_comp.html> e-mail: michelangelo.la at carm.es > > > [[alternative HTML version deleted]] > > > ______________________________________________ > 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. >