jeudi 12 novembre 2020

Making two new variables with case_when or else if statement (R coding)

I need to make some changes to the data frame to be able to create a visual that I want, but I'm stuck. Down below is how the data frame looks like. What I want to do is to make a new variable named 'article'. The values of this variable will be sum_pageviews of the 'Article Based' values from the 'Page' column. Likewise, another variable will be 'info', and its values will be sum_pageviews from 'Informational Based' in Page variable. Then the length of the data frame will be 8 in the end without the repetitiveness of department, and that's what I want to see.

enter image description here

Image down below is how new dataframe is supposed to be look like. I entered on Excel, but I'd like to know code in R.

enter image description here

--> I think I should start with

sum_views%>%group_by(department)%>%mutate

then ifelse or case_when statement, but no idea. Please let me know the codes. Thanks in advance

Aucun commentaire:

Enregistrer un commentaire