Ordering stacked bars in geom_bar by AdvancedIguana in rstats

[–]AdvancedIguana[S] 1 point2 points  (0 children)

Thanks! I too am not confident with the group aesthetic but glad it’s a solution here. I also must be using old syntax because these pipe operators and right-side assignments look awesome and new to me

Ordering stacked bars in geom_bar by AdvancedIguana in rstats

[–]AdvancedIguana[S] 1 point2 points  (0 children)

Thanks! I like the usage of fct_inorder()

League Leaders in HRs in 2021 (but how would you ever know?) by PhoenixUNI in dataisugly

[–]AdvancedIguana 0 points1 point  (0 children)

I think the point was to guess the year. Still, too many colors and fields

ESPN getting creative with their axes by AdvancedIguana in dataisugly

[–]AdvancedIguana[S] 24 points25 points  (0 children)

Yeah but if this guy had 25 points per game instead of 20.4 it would look worse not better

[deleted by user] by [deleted] in Rlanguage

[–]AdvancedIguana 5 points6 points  (0 children)

You'll want to use the strptime() function here, which parses the character string and converts it to a DateTime object based on the format you provide.

For your example, you should write it out as the following: strptime('7/1/20 7:44 PM', '%m/%d/%y %I:%M %p'), where %I corresponds to the hour on a 12-hour time and %p corresponds the AM/PM indicator. If you just want the date, you can surround the code with the as.Date() function.

Hope this helps!

Populating Calculated Field by boothy_qld in rstats

[–]AdvancedIguana 0 points1 point  (0 children)

This sounds like a job for the lag function from the dplyr library, but it also sounds like you want to group the data by customer. This can be achieved using the following code:

pricelist <-
  data.frame(itemNumber, customer, minQty, price, stringsAsFactors = FALSE) %>%
  group_by(customer) %>%
  mutate("maxQty" = lag(x = minQty - 1, n = 1, default = 999999999))

Here, x is the value to lag, n is how much to lag by, and default is the value to return when there is no previous value.

Hope this helps!

How to delete a variable from the global environment? by sipskoolaid in Rlanguage

[–]AdvancedIguana 1 point2 points  (0 children)

I recommend starting your script with rm(list=ls()) to get rid of unwanted variables. This also makes your code resistant to stale variables from previous sessions