Re: [R-sig-eco] Replacing values in a data frame
Maybe: A$X2[A$X21] - 1 Peter -- Péter Sólymos, Dept Biol Sci, Univ Alberta, T6G 2E9, Canada AB soly...@ualberta.ca, Ph 780.492.8534, http://psolymos.github.com Alberta Biodiversity Monitoring Institute, http://www.abmi.ca Boreal Avian Modelling Project, http://www.borealbirds.ca 2012/10/25 Manuel Spínola mspinol...@gmail.com: Dear list members, I want to replace the values of a numerical variable in a data frame called A. A X1X2 2 1.5 31 41.2 How to replace any value greater than 1 by the value 1 in the variable X2. Thank you very much in advance. Best, Manuel -- *Manuel Spínola, Ph.D.* Instituto Internacional en Conservación y Manejo de Vida Silvestre Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA mspin...@una.ac.cr mspinol...@gmail.com Teléfono: (506) 2277-3598 Fax: (506) 2237-7036 Personal website: Lobito de río https://sites.google.com/site/lobitoderio/ Institutional website: ICOMVIS http://www.icomvis.una.ac.cr/ [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Replacing values in a data frame
Hi, 2012/10/25 Manuel Spínola mspinol...@gmail.com: Dear list members, I want to replace the values of a numerical variable in a data frame called A. A X1X2 2 1.5 31 41.2 How to replace any value greater than 1 by the value 1 in the variable X2. I think you made a typo? I'm assuming you want to replace values in column X1 that are greater than 1 with the values in X2? All of your X1 are greater than 1 in your test example, but: with(A, ifelse(X1 1, X2, X1)) or A$X1[A$X1 1] - A$X2[A$X1 1] Sarah -- Sarah Goslee http://www.functionaldiversity.org ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Replacing values in a data frame
You can also try using ifesle() A$X2 - ifelse(A$X21, 1, A$X2) On Thu, Oct 25, 2012 at 2:08 PM, Peter Solymos soly...@ualberta.ca wrote: Maybe: A$X2[A$X21] - 1 Peter -- Péter Sólymos, Dept Biol Sci, Univ Alberta, T6G 2E9, Canada AB soly...@ualberta.ca, Ph 780.492.8534, http://psolymos.github.com Alberta Biodiversity Monitoring Institute, http://www.abmi.ca Boreal Avian Modelling Project, http://www.borealbirds.ca 2012/10/25 Manuel Spínola mspinol...@gmail.com: Dear list members, I want to replace the values of a numerical variable in a data frame called A. A X1X2 2 1.5 31 41.2 How to replace any value greater than 1 by the value 1 in the variable X2. Thank you very much in advance. Best, Manuel -- *Manuel Spínola, Ph.D.* Instituto Internacional en Conservación y Manejo de Vida Silvestre Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA mspin...@una.ac.cr mspinol...@gmail.com Teléfono: (506) 2277-3598 Fax: (506) 2237-7036 Personal website: Lobito de río https://sites.google.com/site/lobitoderio/ Institutional website: ICOMVIS http://www.icomvis.una.ac.cr/ [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Re: [R-sig-eco] Replacing values in a data frame
Thank you very much Tim. Best, Manuel 2012/10/25 Tim Meehan tme...@gmail.com You can also try using ifesle() A$X2 - ifelse(A$X21, 1, A$X2) On Thu, Oct 25, 2012 at 2:08 PM, Peter Solymos soly...@ualberta.cawrote: Maybe: A$X2[A$X21] - 1 Peter -- Péter Sólymos, Dept Biol Sci, Univ Alberta, T6G 2E9, Canada AB soly...@ualberta.ca, Ph 780.492.8534, http://psolymos.github.com Alberta Biodiversity Monitoring Institute, http://www.abmi.ca Boreal Avian Modelling Project, http://www.borealbirds.ca 2012/10/25 Manuel Spínola mspinol...@gmail.com: Dear list members, I want to replace the values of a numerical variable in a data frame called A. A X1X2 2 1.5 31 41.2 How to replace any value greater than 1 by the value 1 in the variable X2. Thank you very much in advance. Best, Manuel -- *Manuel Spínola, Ph.D.* Instituto Internacional en Conservación y Manejo de Vida Silvestre Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA mspin...@una.ac.cr mspinol...@gmail.com Teléfono: (506) 2277-3598 Fax: (506) 2237-7036 Personal website: Lobito de río https://sites.google.com/site/lobitoderio/ Institutional website: ICOMVIS http://www.icomvis.una.ac.cr/ [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology -- *Manuel Spínola, Ph.D.* Instituto Internacional en Conservación y Manejo de Vida Silvestre Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA mspin...@una.ac.cr mspinol...@gmail.com Teléfono: (506) 2277-3598 Fax: (506) 2237-7036 Personal website: Lobito de río https://sites.google.com/site/lobitoderio/ Institutional website: ICOMVIS http://www.icomvis.una.ac.cr/ [[alternative HTML version deleted]] ___ R-sig-ecology mailing list R-sig-ecology@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-ecology