• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: else if statement to create a new column

Resolved: else if statement to create a new column

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a data frame of multiple columns. I want to create a new colomn called second.indicator with the following :
second.indicator == -1 if il.count.description + un.count.description > elle.count.description + une.count.description
second.indicator == 0 if il.count.description + un.count.description) == elle.count.description + une.count.description
else second.indicator == 1
the output is many error messages : ‘second.indicator’ not found / Error: unexpected ‘}’ in ” }”

Answer:

You cannot use if-statements inside mutate like that (for multiple reasons); instead you could use case_when:

If you have better answer, please add a comment about this, thank you!

dataframe if-statement r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: how to change date format from 201904 to Apr-19 in excel

01/04/2023

Resolved: Iterator for custom Hashtable C#

01/04/2023

Resolved: Azure Cognitive Search – Do sematic search configuration support binding content field to content type in a Edm.ComplexType?

01/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.