Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

How to reduced length of code ifelse statement

$
0
0

I would like to calculate total page number, based on total number of days. Example: 0 to 25 days page 1, 26 to 50 days page 2 etc…! I am using below method.

df$totalpage <- ifelse(df$days >=0 & df$days<=25,1,
                      ifelse(df$days >=26 & df$days<=50,2,"Something wrong"))

Is there any other method to do the same, as if I have more days (> 365 ) I have to add many ifelse which makes code lengthy. any suggestion would be helpful.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



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