Does anybody know of a way to create a new data frame that contains the information of specific columns from a master data frame that has multiple columns? I have a master dataframe and I'm trying to run various tests (regression, ANOVA...etc.,) on specific columns in the data frame. Any suggestions would be greatly appreciated.
Asked
Active
Viewed 2,275 times
-3
-
Please check this [URL](http://stackoverflow.com/help) it will be useful to lift your content quality up – Willie Cheng Jun 15 '16 at 02:05
-
Welcome to SO! Your question is unfortunately unlikely to be answered in its current state, as @willie implied. The question is very vague, and lacking any context or examples, it sounds like you are asking all of us to "teach you R". I strongly suggest you read [SO help on minimal/complete questions](http://stackoverflow.com/help/mcve) as well as a great answer on [reproducible examples](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – r2evans Jun 15 '16 at 03:26
-
Why would you need to create a new data frame for running linear models in the first place? Here's how you run ANOVA with iris dataset: `aov(Petal.Length ~ Species, data=iris)`. Here's how you run a linear regression: `lm(Petal.Length ~ Sepal.Length, data=iris)`. Refer to http://www.statmethods.net/stats/regression.html to understand the linear model syntax for R. – Adam Quek Jun 15 '16 at 04:39
1 Answers
1
if you want to choose columns 3,12 and 15 from the old DF:
newDF <- oldDF[,c(3,12,15)]
if you want to remove columns 3,12 and 15 from the old DF:
newDF <- oldDF[,-c(3,12,15)]

Zahiro Mor
- 1,708
- 1
- 16
- 30