[R] help to add a new column filled with value 1

Phil Spector spector at stat.berkeley.edu
Tue Nov 9 18:28:31 CET 2010


Mohan -
     Suppose your data frame is named "df". Try this:

data.frame(df[,1],1,df[,2:5])

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu




On Tue, 9 Nov 2010, Mohan L wrote:

> Dear All,
>
> I have a data frame with  5 column and 201 row data. I want to add one
> more column between column 1 and 2 with value of 1. So the new column
> has to be the second column filled with 1. Any help will be
> appreciated.
>
> Thanks for your time.
>
>
> Thanks & Rg
> Mohan L
>
> ______________________________________________
> 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