Quantcast
Channel: Active questions tagged r - Stack Overflow
Browsing all 201839 articles
Browse latest View live

How to change the polynomial order in a for-loop using the poly R function?

I would like to fit a regression by trying different polynomials, and I tried running this loop:for (p_order in 1:9) { assign(paste("RD0", p_order, sep = ""), electricity_price ~ d1 + gas_price +...

View Article


Generate a new variable based on the time of another variable value

I have a dataset likes like belowID. Invoice. Date of Invoice. paid or not. 1 1 10/31/2019 yes 1 1 10/31/2019 yes 1 2 11/30/2019 no 1 3 12/31/2019 no 2 1 09/30/2019 no 2 2 10/30/2019 no 2 3 11/30/2019...

View Article


Build a cron job running first weekday of every 3 months

I want to develop a cron job in Ubuntu using R with it cronR package. That job would run on the first Sunday of every 3 months (this 3 should be a variable). However the cronR package does not give any...

View Article

Counting how many point are in the polygon of region [R]

I would like to ask how to calculate number of point that are in some region when we have longtitue and latitude variables of point and polygon of country and its regions.I provided example below: I...

View Article

What is the best way to count values within columns to create a summary table?

I have a tbl_df that has several columns that have multiple values in them. I am looking to use the values in the columns to create several columns. After that, I'm looking to summarize the columns....

View Article


In R when using count function, how to just extract the int value from the...

For example:data("cars") count(cars) I will get a tibble of 1x1, but I would like to assign the count which was 54 into a variable to use later. If I use Select I also get a tibble back, I just want a...

View Article

Merge data.tables while keeping original order in R

I would like to merge two data tables while keeping the original order of the data tables. I would also like to have a final column to say whether the two ids match each other. All of this while...

View Article

How to use the Spread function using only one value of the target column?

We have the following data frame a with something like this:> a google_prod Value 1 categoria ML 2 google 120 3 youtube 24 4 categoria AO 5 google 2 6 youtube 0 7 categoria ML 8 google 27 9 youtube...

View Article


Calculate distance between one individual to every predator on same date

I am calculating the distance between moose and wolves using UTM33 coordinates over the period of 2 years (large dataset) in R. I want to have a final table that gives me something like mooseID...

View Article


How to find UNIX times corresponding to a particular date in a very large...

I have a very large (10 million row x 12 column) comma-delimited text file. The first column contains UNIX times (in seconds to 2 d.p.)I would like to extract all rows corresponding to a particular...

View Article

Image may be NSFW.
Clik here to view.

Translating a mathematical equation into code

I am really really new to the R language. Can anyone help me translate this equation to code?Note that the variables C, M, and R will correspond to an Excel file of numerical values, so I assume I...

View Article

R - lapply() and DataFrame

is it possible to use lapply() to dynamically fetch condition and then apply to data frame? For demonstration purpose, I have simplified examplee.g. cond <- list("cyl==6", "mpg >= 21", "hp==110...

View Article

How to set the estimate argument correctly for roc_auc() function in...

I want to compute the AUC for a model. library(yardstick) data(two_class_example) This code works. roc_auc( two_class_example, truth = truth, Class1, options = list(smooth = TRUE) ) I like to specify...

View Article


Issues with logit regression in r

I am trying to run a logit regression and I tried two approaches:m.logit <- glm(p4 ~ scale(log(gdp,orthodox,swb)), data = happiness, family = binomial("logit")) summary(m.logit) Throws: Error in...

View Article

How to assign a numerical code to a string based on a set of keywords in R

For example, I have an array of data in which some text descriptions are given as follows:big Pool House1 storey Warehouse multiple Storage poolNow, I want to code the text descriptions based on the...

View Article


Image may be NSFW.
Clik here to view.

How can I use R to see the error metrics in HydroGOF?

under the two conditions of "Simulated" and "Measured" (See the image),I want to calculate some error metrics such as Nash-Sutcliffe efficiency (NSE) or root mean square error (RMSE), but I don't know...

View Article

Reading an sbml file using xml2 in R using xpath

I am really new to xml and I am trying to read an sbml file using the xml2 package in R.The demo sbml file is taken from the sbml main page.I am confused as to how to search for a node using the...

View Article


Image may be NSFW.
Clik here to view.

Apply a function across all combinations of variables and store the plot in a...

I have some data (iris dataset) and I also have a plotting function called decisionplot. My question is how can I apply the decisionplot function (which outputs a ggplot plot) to all combinations of...

View Article

return column name when value above threshold

This is a follow-up to an earlier question: Return column name for max functionethnic <- c("white", "black", "hispanic", "asian", "other") ethnicity$ethnicity <- ethnic[max.col(ethnicity[ethnic],...

View Article

Do previous lines calculated influence the sequential lines in a loop for R?

I have this codex=c(T,T,F,T,F) for (i in 1:5){ if(i > 1 & i < 5){ x[i ] = x[i-1] & x[i+1] & x[i] print(x) } else if(i < 5){ x[i] = !x[i] | !x[i+1] } } I am trying to figure out the...

View Article
Browsing all 201839 articles
Browse latest View live