Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 143127

R is a free, open source programming language and software environment for statistical computing and graphics.

3 votes
Accepted

Assign 0 or 1 with different probabilities conditional on another column in R

example_data$exposure <- ifelse(example_data$outcome == 1, sample(0:1, nrow(example_data), prob = c(0.1, 0.9), replace = T), sample(0:1 …
minem's user avatar
  • 952
1 vote
Accepted

Streamline R code for Shiny usage

Changed a little bit input data: n <- 60 set.seed(21) a <- data.frame( DATE = rev(seq.Date(as.Date("2018-01-01"), as.Date("2018-06-15"), "days"))[1:n], OPERATION_STATUS = sample(c("PASS","FA …
minem's user avatar
  • 952
2 votes
Accepted

Checking the presence of certain variables in a dataframe

I would do something like this: tt <- function() { naI <- sapply(input_df[, c('var_in', 'var_out')], function(x) all(is.na(x))) if (sum(naI) == 2) { stop("both var_in and var_out are complete …
minem's user avatar
  • 952
1 vote
Accepted

transform columns to binary encoded columns in R

If we test on larger vector your approach is quite slow: test_vec <- 1:1e5 system.time(v1 <- encode_binary(test_vec, name = "binary_x1_")) # user system elapsed # 22.23 0.08 22.37 Based on t …
minem's user avatar
  • 952
1 vote

R code for reading tabular data files and plotting light curves of modeled stars

But from your code it seems that the biggest problem is that you are repeatedly reading the same files into R. This should be done once separately. …
minem's user avatar
  • 952
1 vote
Accepted

R code for reading tabular data files and plotting light curves of modeled stars

for minimal code changes: prof_num <- 1:4 prof.path <- file.path('LOGS_A1a', paste0('profile', prof_num, '.data')) DF.profile <- lapply(prof.path, function(x) read.table(x, header = 1, skip = 5)) for …
minem's user avatar
  • 952
3 votes

Finding values below a threshold

get a(result) for each Value } set.seed(42) Value2 <- sample.int(1e5) system.time(r2 <- fun_2(Value2)) # 36.64 system.time(r3 <- fun_3(Value2)) # 0.03 all.equal(r2, r3) # [1] TRUE OR with base R: …
minem's user avatar
  • 952
2 votes

Summations zu.mpfr and zstar based on a probability sample

After some testing, I would suggest that you decrease the precBits, because that changes a lot: precBits = 10000 I did not see any (significant) changes in results using 10000. Also, you can try t …
minem's user avatar
  • 952
1 vote

How can I can do better with my R code to analyze word counts

What is kmer_list ? what is k? we can not test the code... But, that said, I adjusted 3 functions, without testing them, maybe they give some speedup: expected_high_markov_var <- function(kmer, counts …
minem's user avatar
  • 952
1 vote
Accepted

Group uncorrelated variables into subsets using correlation matrix

rownames(corr) <- colnames(corr) <- 1:ncol(corr) vars <- rownames(corr) vars <- as.integer(vars) list_data2 <- list() list_data2[[1]] <- vars[1] t1 <- proc.time() for (i in 2:length(vars)) { added …
minem's user avatar
  • 952
5 votes
Accepted

Random Weighted Classifier in R

Some improvements: random_weighted_classifier2 <- function(n = 1, weightA, weightB, weightC){ x <- sample(1:100, n, replace = T) / 100 i1 <- x <= weightA i2 <- x > weightA & x <= (weightA + wei …
minem's user avatar
  • 952
1 vote

Statistical sampling from a vector

Your code is quite good. Simulations is hard to vectorize. The largest slowdown here is the repeated calling of rbind in loop. It is faster to crate list of vectors and concatenate the results at the …
minem's user avatar
  • 952
1 vote
Accepted

Flagging system: Check for changing values in a data frame

I reduced the example data, for easier viewing # new example data: mydata <- data.frame(ta = 1:13) mydata[2:3, 1] <- 1L mydata[6:12, 1] <- 2L n <- 3 # how many equal values we need require(data.tab …
minem's user avatar
  • 952
1 vote

pattern matching, replacement and for loop optimization in R

You can try something like this: # function for string preperation: preperString <- function(x) { require(stringr) x <- str_to_lower(x) x <- str_trim(x) x } setDT(loc_df) # convert data.fram …
minem's user avatar
  • 952
0 votes
Accepted

Average calculation

# GENERATE data nmax <- TimeSpan[nrow(TimeSpan), ] tSEQ <- seq(as.POSIXct("16/02/2014 0:00", format = "%d/%m/%Y %H:%M"), to = nmax, by = '5 s') n <- length(tSEQ) X <- data.frame(tSEQ) set. …
minem's user avatar
  • 952

15 30 50 per page