[R] changing column names in a dataframe

GlenB glnbrntt at gmail.com
Tue Apr 6 10:11:31 CEST 2010



jda wrote:
> 
> I have imported data from an Excel spreadsheet.  Columns in that
> spreadsheet are named "name", "x", and "y", and several sets of those
> columns appear in the worksheet.  For example:
> 
> name  x y name   x y
> test1 1 3 test2  4 4
> test1 2 2 test2  5 5
> test1 3 1 test2  6 6
> 
> When I import these data into R, into a dataframe, I end up with something
> like this:
> 
>   name  x y name1  x1 y1
> 1 test1 1 3 test2  4  4
> 2 test1 2 2 test2  5  5
> 3 test1 3 1 test2  6  6
> 
> I -cannot- change the excel file, and must work with the data and labels
> as they appear in R.  I would like to end up with a dataframe that looks
> more like this:
> 
>   x-test1  y-test1  x-test2  y-test2
> 1 1        3        4        4
> 2 2        2        5        5
> 3 3        1        6        6
> 

if you're using one of the read functions (like read.csv) to import the
data, there's a col.names argument.

Glen
-- 
View this message in context: http://n4.nabble.com/changing-column-names-in-a-dataframe-tp1752034p1752531.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list