Bob Green
2006-Jun-19 12:11 UTC
[R] saving rounded numbers as a new variable in a dataframe
A basic question, but one that eludes me. I have created a new variable $numurder, which I have rounded off. I want to save the rounded off version of this variable to an existing datafile called 'ngri.csv' . numurder <-c((murder*no.of.cases)/100) [[1]] [1] 48.952 112.073 182.160 974.610 122.140 663.432 150.856 18.988 137.925 198.045 68.930 203.148 30.056 100.955 round(numurder, 0) [1] 49 112 182 975 122 663 151 19 138 198 69 203 30 101 Advice regarding how to do this is appreciated, Bob
Neuro LeSuperHéros
2006-Jun-19 12:20 UTC
[R] saving rounded numbers as a new variable in a dataframe
Hi 1-Please read this: R Data Import/Export cran.r-project.org/doc/manuals/R-data.pdf 2-This is the code: rounded <-round(numurder, 0) write.csv(rounded,"c:/ngri.csv") Neuro>From: Bob Green <bgreen at dyson.brisnet.org.au> >To: r-help at stat.math.ethz.ch >Subject: [R] saving rounded numbers as a new variable in a dataframe >Date: Mon, 19 Jun 2006 22:11:57 +1000 > > > >A basic question, but one that eludes me. I have created a new variable >$numurder, which I have rounded off. I want to save the rounded off version >of this variable to an existing datafile called 'ngri.csv' . > > numurder <-c((murder*no.of.cases)/100) >[[1]] > [1] 48.952 112.073 182.160 974.610 122.140 663.432 150.856 18.988 >137.925 198.045 68.930 203.148 30.056 100.955 > > >round(numurder, 0) > [1] 49 112 182 975 122 663 151 19 138 198 69 203 30 101 > > >Advice regarding how to do this is appreciated, > >Bob > >______________________________________________ >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
Petr Pikal
2006-Jun-19 12:49 UTC
[R] saving rounded numbers as a new variable in a dataframe
Hi On 19 Jun 2006 at 8:20, Neuro LeSuperH?ros wrote: From: Neuro LeSuperH?ros <neuro3000 at hotmail.com> To: bgreen at dyson.brisnet.org.au, r-help at stat.math.ethz.ch Date sent: Mon, 19 Jun 2006 08:20:16 -0400 Subject: Re: [R] saving rounded numbers as a new variable in a dataframe> Hi > > 1-Please read this: R Data Import/Export > cran.r-project.org/doc/manuals/R-data.pdf > 2-This is the code: > > rounded <-round(numurder, 0) > write.csv(rounded,"c:/ngri.csv")this will erase former ngri.csv and write a new ngri.csv containing only rounded variable!!! Let ngri is data frame from which you have murder and other variables then write.csv(data.frame(nmurder=rounded, ngri),"c:/ngri.csv") shall be better choice. HTH Petr> > Neuro > > > >From: Bob Green <bgreen at dyson.brisnet.org.au> > >To: r-help at stat.math.ethz.ch > >Subject: [R] saving rounded numbers as a new variable in a dataframe > >Date: Mon, 19 Jun 2006 22:11:57 +1000 > > > > > > > >A basic question, but one that eludes me. I have created a new > >variable $numurder, which I have rounded off. I want to save the > >rounded off version of this variable to an existing datafile called > >'ngri.csv' . > > > > numurder <-c((murder*no.of.cases)/100) > >[[1]] > > [1] 48.952 112.073 182.160 974.610 122.140 663.432 150.856 > > 18.988 > >137.925 198.045 68.930 203.148 30.056 100.955 > > > > > >round(numurder, 0) > > [1] 49 112 182 975 122 663 151 19 138 198 69 203 30 101 > > > > > >Advice regarding how to do this is appreciated, > > > >Bob > > > >______________________________________________ > >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 > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz