Hello, I would like to access my data frame without one variable. E.g.:> colnames(x)[1] "Besch" "Ang.m" "Arb.m" "i10" "Umsatz" "arbstd" I can try x[,-1], but this variable must be called by it??s name. x[,-"Besch"] x[,!"Besch"] attach(x) x[-Besch] ... ... does not work. I could not found a solution of this little problem in any scripts about R and in google. Should I type in x[,c("Ang.m","Arb.m","i10","Umsatz","arbstd")] to access my data frame without variable "Besch", or is there any better solution. Some of my data frames has ~100 variables and so is x[,c(...)] a little bit exhausting. Thanks for any help, Matthias
Hi On 17 May 2004 at 10:46, TEMPL Matthias wrote:> Hello, > > I would like to access my data frame without one variable. > > E.g.: > > colnames(x) > [1] "Besch" "Ang.m" "Arb.m" "i10" "Umsatz" "arbstd" > > I can try x[,-1], but this variable must be called by it??s name. >x[,names(x)!="Besch"] should work but maybe there is some better solution Cheers Petr> x[,-"Besch"] > x[,!"Besch"] > attach(x) > x[-Besch] > ... > ... > does not work. > > > I could not found a solution of this little problem in any scripts > about R and in google. > > Should I type in x[,c("Ang.m","Arb.m","i10","Umsatz","arbstd")] to > access my data frame without variable "Besch", or is there any better > solution. > > Some of my data frames has ~100 variables and so is x[,c(...)] a > little bit exhausting. > > Thanks for any help, > > Matthias > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.htmlPetr Pikal petr.pikal at precheza.cz
Dear Matthias, you could try something like: x <- matrix(rnorm(30*6), 30, 6) colnames(x) <- c("Besch", "Ang.m", "Arb.m", "i10", "Umsatz", "arbstd") your.choice <- "Besch" x[,match(your.choice, colnames(x))] x[,-match(your.choice, colnames(x))] I hope this helps. Best, Dimitris ---- Dimitris Rizopoulos Doctoral Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/16/396887 Fax: +32/16/337015 Web: http://www.med.kuleuven.ac.be/biostat/ http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm ----- Original Message ----- From: "TEMPL Matthias" <Matthias.Templ at statistik.gv.at> To: <r-help at stat.math.ethz.ch> Sent: Monday, May 17, 2004 10:46 AM Subject: [R] Accessing data> Hello, > > I would like to access my data frame without one variable. > > E.g.: > > colnames(x) > [1] "Besch" "Ang.m" "Arb.m" "i10" "Umsatz" "arbstd" > > I can try x[,-1], but this variable must be called by it??s name. > > x[,-"Besch"] > x[,!"Besch"] > attach(x) > x[-Besch] > ... > ... > does not work. > > > I could not found a solution of this little problem in any scriptsabout R and in google.> > Should I type in x[,c("Ang.m","Arb.m","i10","Umsatz","arbstd")] toaccess my data frame without variable "Besch", or is there any better solution.> > Some of my data frames has ~100 variables and so is x[,c(...)] alittle bit exhausting.> > Thanks for any help, > > Matthias > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html
Hoi TEMPL, --On maandag 17 mei 2004 10:46 +0200 TEMPL Matthias <Matthias.Templ at statistik.gv.at> wrote:> Hello, > > I would like to access my data frame without one variable. > > E.g.: >> colnames(x) > [1] "Besch" "Ang.m" "Arb.m" "i10" "Umsatz" "arbstd" > > I can try x[,-1], but this variable must be called by it??s name. > > x[,-"Besch"] > x[,!"Besch"] > attach(x) > x[-Besch] > ... >Try x2 <- subset(x, select=-Besch) kind regards, Paul -- Paul Lemmens NICI, University of Nijmegen ASCII Ribbon Campaign /"\ Montessorilaan 3 (B.01.05) Against HTML Mail \ / NL-6525 HR Nijmegen X The Netherlands / \ Phonenumber +31-24-3612648 Fax +31-24-3616066
Apparently Analagous Threads
- [LLVMdev] Will any pass change simple return branch into select/return pair?
- Creating variables on the fly
- Interdependencies of variable types, logical expressions and NA
- Interdependencies of variable types, logical expressions and NA
- Insert rows in between dataframes