Quantcast
Viewing all articles
Browse latest Browse all 206473

Create a Boolean column by coercing factors to logical types in dataframe?

My dataframe looks like this:

  location       eco    

  Germany        eco    
  Netherlands    eco    
  USA            not-eco 
  Dubai          not-eco 

I would like to create a new column in the dataframe and display TRUE if the location is "eco" and display FALSE if location is "not-eco". The result should look like this:

  location       eco        logical

  Germany        eco        TRUE
  Netherlands    eco        TRUE
  USA            not-eco    FALSE
  Dubai          not-eco    FALSE

How to do this with R?


Viewing all articles
Browse latest Browse all 206473

Trending Articles



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