Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert string booleans expressed in local language into boolean

I have a large dataset collected in local language, where each bolean column use the word "PRAWDA" for TRUE and "FAŁSZ" for FALSE.

So far, the dataframe stores those values as a column with factors with 2 levels: "FAŁSZ" and "PRAWDA". My aim is to have the column which will be full of booleans, not string values.

How could I convert all the booleans expressed in Polish into English ones?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

If it is just a boolean, use == to check for ‘PRAWDA’, which returns TRUE for those cases that match ‘PRAWDA’ and FALSE otherwise. As there is only two values, this should be sufficient

df1$col2 <- df1$col1 == 'PRAWDA'

If there are multiple columns, use a loop

df1[] <- lapply(df1, function(x) if(all(x %in% c('PRAWDA', 'FALSZ'), na.rm = TRUE)) x == 'PRAWDA' else x)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading