[Solved] Using factor levels with geom_rect

I got some help after asking the same question on the comp.lang.r.general mailing list (http://permalink.gmane.org/gmane.comp.lang.r.general/313656). I ended up adding the following: nodelist <- sort(levels(flatdata$value)) and then using geom_rect(aes(ymin=as.Date(“8-Apr-2014″, format=”%d-%b-%Y”), ymax=as.Date(“30-Apr-2014″, format=”%d-%b-%Y”), xmin=which(nodelist==”node004″)-0.5, xmax=which(nodelist==”node004″)+0.5, fill=”red”, alpha=0.25)) solved Using factor levels with geom_rect

[Solved] What is the appropriate machine learning algorithm for a restaurant’s sales prediction? [closed]

Pretty general question, requiring more than a stack overflow response. The first thing I’d consider is setting up a predictive algorithm like the linear regression you spoke of. You can also add a constant to it, as in mx+b where the B is the known quantity of food for reservations. So you would run linear … Read more

[Solved] R: Is there a function to clean factor levels? characters columnwise in a data frame? [closed]

Just use the internal bits from janitor::clean_names(): # #’ ‘Clean’ a character/factor vector like `janitor::clean_names()` does for data frame columns # #’ # #’ Most of the internals are from `janitor::clean_names()` # #’ # #’ @param x a vector of strings or factors # #’ @param refactor if `x` is a factor, return a ref-factored … Read more

[Solved] Label or score outliers in R

Here’s some really simple outlier detection (using either the boxplot statistics or quantiles of the data) that I wrote a few years ago. Outliers But, as noted, it would be helpful if you’d describe your problem with greater precision. Edit: Also you say you want row-wise outliers. Do you mean to say that you’re interested … Read more

[Solved] Fix incomplete character string for year “2016” from “0016” in R [closed]

Kindly go through following R console code snippet: > dates <- c(“10/23/16”, “10/24/16”) > dates [1] “10/23/16” “10/24/16” > Dates <- as.Date(dates, + format = “%m/%d/%y”) > Dates [1] “2016-10-23” “2016-10-24″ Hope it works for you! solved Fix incomplete character string for year “2016” from “0016” in R [closed]

[Solved] Scraping data off site using 4 urls for one day using R

You can turn all the tables into a wide data frame with list operations: library(rvest) library(magrittr) library(dplyr) date <- 20130701 rng <- c(1:4) my_tabs <- lapply(rng, function(i) { url <- sprintf(“http://apims.doe.gov.my/apims/hourly%d.php?date=%s”, i, date) pg <- html(url) pg %>% html_nodes(“table”) %>% extract2(1) %>% html_table(header=TRUE) }) glimpse(plyr::join_all(my_tabs, by=colnames(my_tabs[[1]][1:2]))) ## Observations: 52 ## Variables: ## $ NEGERI / … Read more

[Solved] how to calculate integral with R

In mathematics, an integral is the area under the curve. In your example, you want the area under the curve as defined by position and rate. position <- c(2,34,58) rate <- c(14, 20, 5) plot(position, rate, type=”l”, ylim=c(0, 25)) You can calculate the area under the curve by hand, using the trapezoidal rule: 32*17 + … Read more

[Solved] Magic number in R [closed]

One approach could be like below: num = 1729 sum_of_digits <- sum(as.numeric(unlist(strsplit(as.character(num), split = “”)))) rev_of_sum_of_digits <- as.numeric(paste(rev(strsplit(as.character(sum_of_digits),””)[[1]]),collapse=””)) ifelse(rev_of_sum_of_digits * sum_of_digits == num, “Magic Number!”, “Not a Magic Number!”) Hope this helps! 5 solved Magic number in R [closed]

[Solved] replace the same occurring number with another random number [closed]

I didn’t really get what you mean, but if you want to replace a specific text in your file with a random integer then try: import fileinput from random import randint with fileinput.FileInput(fileToSearch, inplace=True, backup=’.bak’) as file: for line in file: print(line.replace(textToSearch, textToReplace), end=”) with textToReplace = randint(1990, 2020) Hope that helps 7 solved replace … Read more

[Solved] How I can find out 1st and last observation with in group in R for every by group

Here is an option with data.table_1.9.5. Create the “data.table” from “data.frame” using setDT, remove the NA values in “dialled” column (!is.na(dialled)), generate grouping variable by using rleid on “Dialled_nbr”, get the row index of the first and last rows for the levels of grouping variable (.I(c(1L, .N)]), finally subset the “dt1” based on the row … Read more