Re: [R] Converting a string to variable names

2017-11-17 Thread MacQueen, Don
Do you mean that you have One data frame, and it has a bunch of variables within it named P1, P2, P3... or A bunch of data frames names P1, P2, P3... ? I'll assume it's the latter. Here is one way: dfnms < c('P1', 'P2', 'P3') for (nm in dfnms) { tmp <- get(nm) rownames(tmp) <- tmp[[

Re: [R] Converting a string to variable names

2017-11-15 Thread Jim Lemon
Hi Ruiyang, In this case you don't want the "get", just the strings produced by "paste": mydf<-data.frame(col1=LETTERS[1:10],col2=1:10) rownames(mydf)<-paste("P",mydf$col1,sep="") Jim On Thu, Nov 16, 2017 at 9:22 AM, 刘瑞阳 wrote: > Hi, > > Thanks for your reply. > > I just came up with another qu

Re: [R] Converting a string to variable names

2017-11-15 Thread 刘瑞阳
Hi, Thanks for your reply. I just came up with another question about a similar but different thing: Say I have a bunch of data.frame variables named P1,P2,P3… I want to assign them row names according to symbols in the first column, and I want to do this using a for loop. How could I accompli

Re: [R] Converting a string to variable names

2017-11-14 Thread Jim Lemon
Hi Ruiyang, I think you want "get": For (index in seq(1,16)){ plot(x=(a given set of value),y=get(paste(“PC”,as.character(index),sep=“”))) } On Wed, Nov 15, 2017 at 7:43 AM, 刘瑞阳 wrote: > Hi, > Suppose that I want to do a series of plots with the y value for each plot as > PC1, PC2, PC3… How cou