[R] I want my row name to be a variable

Erik Iverson iverson at biostat.wisc.edu
Sun Nov 16 03:08:45 CET 2008


X$Var3 <- row.names(X)

CE.KA wrote:
> Hi R users
> 
> Imagine this data.frame:
>> X
> 
>     Var1    Var2
> A   22       13
> B    5         2
> C    12       8
> D    1        99
> 
> A,B,C,D are the rows names (or index)
> 
> Is there a way to create a new variable in this data frame
> which name is Var3 and which contains the rows names:
> 
>     Var1    Var2    Var3
> A   22       13        A
> B    5         2         B
> C    12       8         C
> D    1        99        D
> 
> I tried as.data.frame(array(x, dim(x), dimnames(x)))
> but it doesn'work
> 
> Sincerely yours
>



More information about the R-help mailing list