Hi I was confused by your example, too and still am a little bit confused, so please excuse me if my example does not answer your question:
You have a data.frame "dat" > dat <- data.frame(colname1 = 1:4, colname2 = 5:8) You have a vector with the colnames of "dat" > namen <- colnames(dat) You want to acess on the values in dat bu using the vector "namen" > for (i in namen) > print(dat[,i]) or > for (i in 1:length(namen)) > print(dat[,namen[i]]) Does that answer your question or is it more complicated? Best regards, Christoph -------------------------------------------------------------- Christoph Buser <[EMAIL PROTECTED]> Seminar fuer Statistik, LEO C13 ETH Zurich 8092 Zurich SWITZERLAND phone: x-41-44-632-4673 fax: 632-1228 http://stat.ethz.ch/~buser/ -------------------------------------------------------------- COMTE Guillaume writes: > Thks for your answer, > > I wish to access colnames by using vars like in my example nom="toto" , if i > type toto in R it will display the column named toto with the values that > the column keep, i wish the same by typing nom, but in my case it shows the > content of the var nom not the values of the column named toto, but "toto". > > I can't be more accurate because i'm unable to formulate it an other way. > > another example: > > I've got a set of colnames : > > > nomalarme1 > [1] "AirFlowFailure" "AirSensorFailure" "GasLeek" > [4] "SuddenPressureDrop" "InletPressureToLow" "PressureRiseFailure" > [7] "HoseLeakTestFailure" "o50DCVoltageToLow" > > All of these names identify colnames (like AirFlowFailure). > > My problem is if i do > > For (i in 1:length(nomalarme1)) > { > nomalarme1[i] > } > It will display the names of the columns not the datas, is there is > something that can tell R to show data's that have for colname nomalarme[i], > and not just the colname. > > > Thks for your answer, i've looked into S-Poetry and it seems that it isn't > explained there, but my "poor" english maybe have missed it... > > > COMTE Guillaume > > > > > > -----Message d'origine----- > De : Patrick Burns [mailto:[EMAIL PROTECTED] > Envoyé : mardi 16 mai 2006 17:12 > À : COMTE Guillaume > Objet : Re: [R] variable row names > > I don't understand your question, but perhaps the > subscripting section of chapter 1 of S Poetry can > help you. > > > Patrick Burns > [EMAIL PROTECTED] > +44 (0)20 8525 0696 > http://www.burns-stat.com > (home of S Poetry and "A Guide for the Unwilling S User") > > COMTE Guillaume wrote: > > >Hy all, > > > > > > > >I wish to use a variable as rownames for a set of datas. > > > > > > > >By example : > > > > > > > > > > > > > > > >>nom<-"toto" > >> > >> > > > > > > > >>prenom<-"tutu" > >> > >> > > > > > > > >>res<-c(1,2) > >> > >> > > > > > > > >>res<-t(res) > >> > >> > > > > > > > >>res > >> > >> > > > > [,1] [,2] > > > >[1,] 1 2 > > > > > > > >>colnames(res)<-c(nom,prenom) > >> > >> > > > > > > > >>res > >> > >> > > > > toto tutu > > > >[1,] 1 2 > > > > > > > >>nom > >> > >> > > > >[1] "toto" > > > > > > > > > > > > > >I wish to call the rowname by the variable name, in this case it would > >be < nom > or < prenom > , but if i do that it gives me the name of the > >row not the values of it. > > > > > > > >Is this possible or not? > > > > > > > >Thks all. > > > > > > > >COMTE Guillaume > > > > > > > > > > [[alternative HTML version deleted]] > > > >______________________________________________ > >[email protected] mailing list > >https://stat.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide! > >http://www.R-project.org/posting-guide.html > > > > > > > > > > ______________________________________________ > [email protected] mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
