[R] editing a data.frame

From: john.polo <jpolo_at_mail.usf.edu>
Date: Fri, 06 Jun 2008 15:25:15 -0400


dear R users,

the data frame (read in from a csv) looks like this:

        TreeTag     Census    Stage     DBH
1     CW-W740   2001 juvenile     5.8
2     CW-W739   2001 juvenile     4.3
3     CW-W738   2001 juvenile     4.7
4     CW-W737   2001 juvenile     5.4
5     CW-W736   2001 juvenile     7.4
6     CW-W735   2001 juvenile     5.4
...
1501 1.00E-20   2001  adult      32.5

i would like to change values under the TreeTag column. as the last value shows, some of the tags have decimals followed by 2 decimal places. i just want whole numbers, i.e. not 1.00E-20, but 1E-20. i have a rough understanding of regexp and grepped all the positions that have the inappropriate tags. i tried sub() a couple of different ways, like yr1bp$TreeTag[1501]<-sub("1.00", "1", yr1bp$TreeTag[1501]) and after turning yr1bp$TreeTag[1501] into <NA>, yr1bp$TreeTag[1501]<-sub("", "1E-20", yr1pb$TreeTag[1501]) and
sub("", "1E-20", yr1bp$TreeTag[1501])
but it's not working. i guess it has something to do with the data.frame characteristics i'm not aware of or don't understand. would i somehow have to tear apart the columns, edit them, and then put it back together? not that i know how to do that, but i'm wondering out loud.

john



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. Received on Fri 06 Jun 2008 - 20:19:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 06 Jun 2008 - 22:30:47 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive