Issue When I run the following I get an error: sample(c(1,4),5,replace=FALSE) This is the error: Error in sample.int(length(x), size, replace, prob) : cannot take a sample larger than the population when ‘replace = FALSE’ Is there a way to sample

Continue reading# Tag: sampling

## [SOLVED] Sample a proportion of each group with propotional allocation, BUT with a minimum constraint (using dplyr)

Issue This question is a follow up question from this question here I have a population of 6 categories (stratum) and I want in each stratum to take the 10% as a sample. Doing so I take: var = c(rep("A",10),rep("B",10),rep("C",3),rep("D",5),"E","F");var

Continue reading## [SOLVED] Using Python Pandas how to use stratified random sampling where assigning percentage as required for sampling

Issue I have a data set for Group and IDs of the Farmers. I have to select 6 Farmers out of 18 farmers using Stratified Random Sampling where percentage is given for sampling. Group wise percentage as below Date Set:

Continue reading## [SOLVED] Downsample time series whenever abs(difference) since the previous sample exceeds threshold

Issue I have a timeseries of intraday tick-by-tick stock prices that change gradually over time. Whenever there is a small change (e.g. the price increases by $0.01), a new row of data is created. This leads to a very large

Continue reading## [SOLVED] Sampling randomly and non-randomly in one sample

Issue Is there a way to sample X number of random rows and X non-random rows in a single sample? For example, I want to get 1,000 samples of 4 rows of iris. I want to randomly sample 3 rows

Continue reading## [SOLVED] Binning 2D data with circles instead of rectangles – from pandas df

Issue I have a dataframe of x, y data and need to bin it into circles. Ie a grid of circles of certain size and spacing centered on some point. So for example some data would be left out after

Continue reading## [SOLVED] Sampling submatrices in R

Issue Given a matrix like mat > set.seed(1) > mat <- matrix(rbinom(100,1,0.5),10,10) > rownames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:nrow(mat))) > colnames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:ncol(mat))) > mat A1 A2 A3 B4 B5 B6 B7 A8 B9 B10 B1 0 0 1 0 1 0 1

Continue reading## [SOLVED] Sampling submatrices in R

Issue Given a matrix like mat > set.seed(1) > mat <- matrix(rbinom(100,1,0.5),10,10) > rownames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:nrow(mat))) > colnames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:ncol(mat))) > mat A1 A2 A3 B4 B5 B6 B7 A8 B9 B10 B1 0 0 1 0 1 0 1

Continue reading## [SOLVED] What can I do to generate random samples from a distribution of data that I have?

Issue I have data on the amount of minutes that a machine is active. From this data I get the following distribution plot with minutes on the x axis and the count on the y axis: Now I want to

Continue reading## [SOLVED] How to correct error when sampling Cauchy distribution

Issue I’m trying to sample values from a Cauchy distribution, using what is called (I think) inverse transform sampling. My program is as follows: from numpy import* from matplotlib.pyplot import* from scipy.interpolate import interp1d def f(x): return 1 / (pi*(1+x**2))

Continue reading