In: Statistics and Probability
In R dataframes How to select :1/
a/--all columns for 6 cylinder cars with horsepower >=to 100
b/-only columns mpg,cyl,disp and hp for cars with weight >=3000lbs
Install dplyr package and then use filter function to give condition.
Select function to extract the required columns
There is an inbuilt data frame in R mtcars.,executed the same on mtcars dataframe
Rcode for stepA:
step1 <- filter(dataframe, (cylinder ==8 & horsepower >= 100))
b/-only columns mpg,cyl,disp and hp for cars with weight >=3000lbs
Rcode for stepb:
step2 <- filter(dataframe, (weight>=3000))
Requrdcol <- step2 %>%
select(mpg,cyl,disp,hp,wt)
Rscreenshot:
for stepA:
For stepb: