Hi! I have got a variable, say myVar <- matrix( 1:6, 3, 2 ) and a variable that contains the name of the variable, say myVarName <- "myVar" Now, I want to assign rownames to the Variable "myVar". I can do it by rownames( myVar ) <- c( "A", "B", "C" ) but for some reason I want "myVarName" as argument, e.g. rownames( ????( myVarName ) ) <- c( "A", "B", "C" ) How can I do this? Thanks, Arne -- Arne Henningsen Department of Agricultural Economics University of Kiel Olshausenstr. 40 D-24098 Kiel (Germany) Tel: +49-431-880 4445 Fax: +49-431-880 1397 ahenningsen at agric-econ.uni-kiel.de http://www.uni-kiel.de/agrarpol/ahenningsen/
> myVar <- matrix( 1:6, 3, 2 )> myVar [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 > substitute(rownames(X) <- c("A", "B", "C"), list(X=as.name(myVarName))) rownames(myVar) <- c("A", "B", "C") > eval(substitute(rownames(X) <- c("A", "B", "C"), list(X=as.name(myVarName)))) > myVar [,1] [,2] A 1 4 B 2 5 C 3 6 > At Friday 06:23 PM 11/14/2003 +0100, Arne Henningsen wrote:>Hi! > >I have got a variable, say > myVar <- matrix( 1:6, 3, 2 ) >and a variable that contains the name of the variable, say > myVarName <- "myVar" >Now, I want to assign rownames to the Variable "myVar". >I can do it by > rownames( myVar ) <- c( "A", "B", "C" ) >but for some reason I want "myVarName" as argument, e.g. > rownames( ????( myVarName ) ) <- c( "A", "B", "C" ) >How can I do this? > >Thanks, >Arne > >-- >Arne Henningsen >Department of Agricultural Economics >University of Kiel >Olshausenstr. 40 >D-24098 Kiel (Germany) >Tel: +49-431-880 4445 >Fax: +49-431-880 1397 >ahenningsen at agric-econ.uni-kiel.de >http://www.uni-kiel.de/agrarpol/ahenningsen/ > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://www.stat.math.ethz.ch/mailman/listinfo/r-helpTony Plate tplate at acm.org
Try something like this:> m <- matrix(1:6, 3, 2) > mName <- "m" > eval(substitute(rownames(Name) <- LETTERS[1:3],list(Name=as.name(mName))))> m[,1] [,2] A 1 4 B 2 5 C 3 6 HTH, Andy> -----Original Message----- > From: Arne Henningsen [mailto:ahenningsen at agric-econ.uni-kiel.de] > Sent: Friday, November 14, 2003 12:23 PM > To: r-help at stat.math.ethz.ch > Subject: [R] assigning rownames > > > Hi! > > I have got a variable, say > myVar <- matrix( 1:6, 3, 2 ) > and a variable that contains the name of the variable, say > myVarName <- "myVar" > Now, I want to assign rownames to the Variable "myVar". > I can do it by > rownames( myVar ) <- c( "A", "B", "C" ) > but for some reason I want "myVarName" as argument, e.g. > rownames( ????( myVarName ) ) <- c( "A", "B", "C" ) > How can I do this? > > Thanks, > Arne > > -- > Arne Henningsen > Department of Agricultural Economics > University of Kiel > Olshausenstr. 40 > D-24098 Kiel (Germany) > Tel: +49-431-880 4445 > Fax: +49-431-880 1397 > ahenningsen at agric-econ.uni-kiel.de > http://www.uni-kiel.de/agrarpol/ahenningsen/ > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help >
On Fri, 14 Nov 2003, Liaw, Andy wrote:> Try something like this: > > > m <- matrix(1:6, 3, 2) > > mName <- "m" > > eval(substitute(rownames(Name) <- LETTERS[1:3], > list(Name=as.name(mName))))Or in R 1.8.0 mName<-as.name("m") eval(bquote( rownames(.(mName))<-LETTERS[1:3])) -thomas