try this:
colnames(df)<-df_names[1:ncol(df),"name"]
On Sun, Dec 23, 2012 at 8:41 PM, radhi wrote:
> Hi, I've got a dataframe having a code as column name. Addtionally I have
> another dataframe with a two columns (and lots of rows), the first
> containing the code and the second some Text (real
Hi, I've got a dataframe having a code as column name. Addtionally I have
another dataframe with a two columns (and lots of rows), the first
containing the code and the second some Text (real name). Now I'd like to
use the information (pairs of code and name) of the second dataframe to
rename all t
f_names$name[match(names(df),df_names$code)]
A.K.
- Original Message -----
From: Johannes Radinger
To: r-help@r-project.org
Cc:
Sent: Tuesday, December 11, 2012 5:55 AM
Subject: [R] Renaming column names according to another dataframe
Hi,
I've got a dataframe having a code as column n
HI,
Try this:
names(df)<-df_names$name[df_names$code%in%names(df)]
head(df,2)
# Col A Col B Col C
#1 1 1 1
#2 2 2 2
A.K.
- Original Message -
From: Johannes Radinger
To: r-help@r-project.org
Cc:
Sent: Tuesday, December 11, 2012 5:55 AM
Subject: [R] Renam
A","Col
> B","Col D","Col E","Col C"))
>
> names(df)<-df_names$name[match(names(df),df_names$code)]
>
>
> A.K.
>
> - Original Message -
> From: Johannes Radinger
> To: r-help@r-project.org
> Cc:
> Sent: Tue
df <- data.frame(A=(1:10),B=(1:10),C=(1:10))
# my changes to show that order doesn't matter
df_names <- data.frame(code=c("C","A","D","E","B"),name=c("Col C","Col
A","Col D","Col E","Col B"))
names( df ) <- df_names[ match( names( df ) , df_names[ , 'code' ] ) ,
'name' ]
for more detail see
?mat
Hi,
I've got a dataframe having a code as column name.
Addtionally I have another dataframe with a two columns (and lots of
rows), the first
containing the code and the second some Text (real name).
Now I'd like to use the information (pairs of code and name) of the
second dataframe to rename all
First, data is an R function so it is better to avoid it as a name for
another object. For example, use dat instead.
Try this:
data(iris)
dat=iris
colnames(iris)
[1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
colnames(dat)
[1] "Sepal.Length" "Sepal.Width" "Petal.Le
m: David Winsemius [mailto:dwinsem...@comcast.net]
Sent: 31 May 2009 17:11
To: Benny Chain
Cc: r-help@r-project.org
Subject: Re: [R] renaming column names
Cannot reproduce with a toy example:
> data <- data.frame(a=1:3, b=4:6, c=6:8)
> colnames(data) <- c("d","e",&q
Cannot reproduce with a toy example:
> data <- data.frame(a=1:3, b=4:6, c=6:8)
> colnames(data) <- c("d","e","f")
> colnames(data)
[1] "d" "e" "f"
Perhaps you need to produce more detail. Surely offering the results
of dput(a) would not tax the limits of the R-mail server.
--
David
On May
I am trying to rename the column names of a data frame called "data". It has
177 columns. I have used :
colnames(data) <- a
where a is a vector with 177 character names.
I don't get any error message, but the column names don't change because
when I then type :
colnames(data)
I get th
11 matches
Mail list logo