Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

R dplyr select not removing columns

$
0
0

I'm a new user of R and have a very basic question. I'm trying to delete columns using the dplyr select function. It appears to run correctly but then when the data is viewed using head the deleted column still appears, and also a count is still able to be run on this column. I've run this on a very simple test dataset, the outputs are below. Please advise on how to permanently delete the columns from the data. Thanks

> library(dplyr)
> setwd("C:/")
> mydata <- read_csv("test.csv")
Parsed with column specification:
cols(
  Age = col_double(),
  Gender = col_character(),
  `Smoking Status` = col_character()
)
> head(mydata)
# A tibble: 4 x 3
    Age Gender `Smoking Status`
  <dbl> <chr>  <chr>           
1    18 M      Smoker          
2    25 F      Non-smoker      
3    40 M      Ex-smoker       
4    53 F      Non-smoker      
> select(mydata,-Age)
# A tibble: 4 x 2
  Gender `Smoking Status`
  <chr>  <chr>           
1 M      Smoker          
2 F      Non-smoker      
3 M      Ex-smoker       
4 F      Non-smoker      
> head(mydata)
# A tibble: 4 x 3
    Age Gender `Smoking Status`
  <dbl> <chr>  <chr>           
1    18 M      Smoker          
2    25 F      Non-smoker      
3    40 M      Ex-smoker       
4    53 F      Non-smoker      
> mydata %>% 
+ count(Age)
# A tibble: 4 x 2
    Age     n
  <dbl> <int>
1    18     1
2    25     1
3    40     1
4    53     1

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>