Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

R script: Classes of dataframe variables depend on filters

In some cases the class of a variable can change depending on the filter, leading to runtime error in the script. I have a simple sex column (values M and F), and when no filter or selecting only men the variable is a factor or character, but when using a filter to keep only women, the variable in the R dataframe is a logical variable (with FALSE values).

To avoid errors due to changing classes, variables should have classes determined from the whole dataset and not vary as filters vary.
Status: New
Comments
v-qiuyu-msft
Community Support

Hi @patc3-phd,

 

Please share a sample pbix file with us. Do remove sensitive data in the report. Then you can upload it to your OneDrive, paste the share link here. 

 

Best Regards,
Qiuyun Yu

patc3-phd
New Member

Hi @v-qiuyu-msft 

 

Here is a sample pbix: https://normandinbeaudry-my.sharepoint.com/:u:/g/personal/pacoulombe_normandin-beaudry_ca/EYghROp1n6...

 

Sex is coded M and F, and when you filter such that only females remain (e.g., select "F", or age group 18-20), then the class of dataset$Sex becomes a logical (and in all other cases, a factor, as it should be). I think the class of the variable should be determined based on the full dataset.