开发者

Using a result to index a data.frame

开发者 https://www.devze.com 2023-04-11 20:20 出处:网络
I have adata.frame named pp that looks like this: > head(pp) X02RX03NX04KX04NX04RX06IX06NX08JX08PX09OX11O

I have a data.frame named pp that looks like this:

> head(pp)    
            X02R  X03N  X04K  X04N  X04R  X06I  X06N  X08J  X08P  X09O  X11O   
1961-02-28  42.0  43.0  96.2  10.2  13.5  42.4  21.1  79.1   2.7  15.2  14.3  
1962-02-28  17.1  22.7  27.9 140.7  10.0  36.7   8.2  47.2  28.5  31.5  24.0

Separately I am calculating

dmax<-douro[which(douro[,3]== max(douro[,3])),] 

which, for example gives me:

 > dmax   
   name catch corre.gauge  
31 X04K Douro  -0.5157648

Now I want to use the result dmax开发者_JS百科[1] (the name) to plot the respective column of data from pp. In this case I would like to plot pp$X04K. How can I do that in an automatic way (because I am going to repeat this process several times resulting in different columns from pp)?


Joran just edited your post which means I will be asked to reload the page because an answer has been provided... Getting to the heart of the matter, you can extract the column name and pass it on to [ like so:

pp[, as.character(dmax[1,1])]

The comma is not mandatory but play around with it to see how the layout of the result changes.

0

精彩评论

暂无评论...
验证码 换一张
取 消