[R] Adding new column variable to a existing spreadsheet

Christopher W Ryan cryan at binghamton.edu
Sat Apr 24 04:13:02 CEST 2010

You should be aware that if you have read the data from your csv file
into an object in R, generally nothing you do with that object in R
will change your original csv file (this is generally a good thing),
until/unless, you save or write something from R to that csv file
(which is sometimes not a good idea, if you want to preserve what your
original data looked like.)

It would also be helpful if you could post to the list  the lines of
code that you used to do whatever you are describing here in words.
This will get you better answers.

If the dataframe in R into which you read your data is called my.data,
then you could create a new column or variable with a command like

my.data$newcolumn <- [in here put the expression for your new column]

for example:

my.data$newcolumn <- my.data$firstcolumn + my.data$secondcolumn

On Fri, Apr 23, 2010 at 9:49 PM, Carol Gao <carol.gaox at gmail.com> wrote:
> Hi,
> I've got a csv format of file. There are seven columns of variables all
> together, and I've used the diff() function to take the differences between
> the variables in one column. Now I want to add the differences as the 8th
> column variable to the csv file. Is there any way that I can do this?
> Thanks in advance.
> Carol Gao
>        [[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.

More information about the R-help mailing list