0

the object 'customer_profiling_vars' is a dataframe with just variable selected by a clustering algorithm (RSKC) as seen in R output below the R code:

customer_profiling_vars
customer_profiling_vars$Variables

enter image description here

Now, I want to select only those variables to my dataset sc_df_tr_dummified in the above vector of variables from the dataframe 'customer_profiling_vars' using dplyr's 'select' :

customer_df_interprete = sc_df_tr_dummified %>% 
select(customer_profiling_vars$Variables)
glimpse(customer_df_interprete)

I expect to get the variable 'SalePrice' selected.

However some other variable ('PoolArea.576') gets selected which is very weird:

enter image description here

Just to be sure, I tried using SalePrice directly instead of customer_profiling_vars$Variables, it gives what I intended:

enter image description here

What is wrong with select of dplyr? For me , it seems like it has something to do with the factor nature of 'customer_profiling_vars$Variables':

enter image description here

Thanks in advance!

Bharat Ram Ammu
  • 174
  • 2
  • 16
  • 2
    Please edit your post so that it contains code samples instead of images. And yes, this is probably due to `customer_profiling_vars$Variables` being a factor. Try converting it to a character vector first. – MRau Jan 21 '19 at 12:47
  • @MRau Im sorry, but how to convert R outputs to code samples? – Bharat Ram Ammu Jan 21 '19 at 12:52
  • 1
    copy and paste your code instead of making screen captures, it should in fact be easier. Tor format it properly either put 4 spaces in front of code or use the `{}` icon after selecting your code. – moodymudskipper Jan 21 '19 at 12:59
  • 1
    You can also check [this answer](https://meta.stackexchange.com/a/22189) for tips on code formatting or [this one](https://stackoverflow.com/a/5963610/8918309) on how to make a reproducible example – MRau Jan 21 '19 at 13:09
  • @Moody_Mudskipper Lol, that is exactly what I did for code (if you read the question again). I asked about R-output. – Bharat Ram Ammu Jan 21 '19 at 13:10
  • Thanks @MRau , reproducible example answer really helps! – Bharat Ram Ammu Jan 21 '19 at 13:12
  • 1
    well that's not different :), copy and paste it from your console, and common usage here is to add `#` or `#>` to your output, you can also check the *`reprex`* package. – moodymudskipper Jan 21 '19 at 13:22
  • 1
    Great, thanks Moody! Will edit question by using #> and reprex. – Bharat Ram Ammu Jan 21 '19 at 13:25

0 Answers0