subset

How can I get all subsets of a set that respect the order

 ̄綄美尐妖づ 提交于 2019-12-10 11:48:31
问题 I'm looking for a C# example that will give me all subsets of a set while respecting the order. For example I have A,B and would like: A B AB BA Please note that for my purpose AB != BA . The solution should be generic for any input type: List<List<T>> GetSubsets<T>(List<T> originalSet) I've come across some great solutions using bitwise manipulation for AB == BA (e.g Generate all combinations for a list of strings) but so far I have failed to find anything to solve what I described above.

Subset data frame to include only levels of one factor that have values in both levels of another factor

心已入冬 提交于 2019-12-10 11:44:03
问题 I am working with a data frame that deals with numeric measurements. Some individuals have been measured several times, both as juveniles and adults. A reproducible example: ID <- c("a1", "a2", "a3", "a4", "a1", "a2", "a5", "a6", "a1", "a3") age <- rep(c("juvenile", "adult"), each=5) size <- rnorm(10) # e.g. a1 is measured 3 times, twice as a juvenile, once as an adult. d <- data.frame(ID, age, size) My goal is to subset that data frame by selecting the IDs that appear at least once as a

How to slice a vector in c++ and assign to itself?

人走茶凉 提交于 2019-12-10 11:04:30
问题 I would like to know how I can replace the contents of a vector with a subset of that vector, without re-allocating a new vector (every question I have found appears to have the purpose of allocating a new vector) example: vector<int>* testVec = new vector<int>{1, 2, 3, 4, 5}; //do some operation to slice vector, to say {2, 3, 4} without re-allocating //testVec should now have contents {2, 3, 4} 回答1: The question is not clear on the usage scope, but two calls to std::vector::erase would

Generate all possible subgraphs of a directed graph keeping the number of vertices

Deadly 提交于 2019-12-10 10:48:36
问题 I have two lists of vertices: V and S . I would like to generate all possible directed graphs from V and S so, that each vertex from V has only one out-edge and exactly one in-edge, and each vertex from S can have any number of in- and out- edges. Each graph in the result should contain exactly all vertices from V and from S . The result can contain both connected and disconnected graphs. First I thought it was a powerset-related problem, but powerset has many other sets that may contain just

Java containsAll does not return true when given lists

妖精的绣舞 提交于 2019-12-10 10:06:46
问题 I want to check an array is subset of another array. The program prints false, but I expect true. Why isn't containsAll returning true? int[] subset; subset = new int[3]; subset[0]=10; subset[1]=20; subset[2]=30; int[] superset; superset = new int[5]; superset[0]=10; superset[1]=20; superset[2]=30; superset[3]=40; superset[4]=60; HashSet sublist = new HashSet(Arrays.asList(subset)); HashSet suplist = new HashSet(Arrays.asList(superset)); boolean isSubset = sublist.containsAll(Arrays.asList

R: Subsetting a data.frame using a logical vector with $

。_饼干妹妹 提交于 2019-12-10 09:43:12
问题 I'm having trouble understanding both the reason for use and behavior of the $ symbol in subsetting a data.frame in R. The following example was presented in a beginner's class I'm taking (not with a live professor so can't ask there): temp_mat <- matrix(1:9, nrow=3) colnames(temp_mat) <- c('a', 'b', 'c') temp_df <- data.frame(temp_mat) Calling temp_df obviously outputs: a b c 1 1 4 7 2 2 5 8 3 3 6 9 The example given in the course is then: temp_df[temp_df$c < 10] Which outputs: a b c 1 1 4 7

Matching IDs in two datasets

删除回忆录丶 提交于 2019-12-10 03:41:44
问题 I have two sets of data, comprising pre and a post data. Respondents have unique IDs, and I want to create a subset which includes only those who responded to both surveys. Example dataset: pre.data <- data.frame(ID = c(1:10), Y = sample(c("yes", "no"), 10, replace = TRUE), Survey = 1) post.data <- data.frame(ID = c(1:3,6:10), Y = sample(c("yes", "no"), 8, replace = TRUE), Survey = 2) all.data <- rbind(pre.data, post.data) I have the following function: match <- function(dat1, dat2, dat3){

jq: selecting a subset of keys from an object

a 夏天 提交于 2019-12-10 03:34:12
问题 Given an input json string of keys from an array, return an object with only the entries that had keys in the original object and in the input array. I have a solution but I think that it isn't elegant ( {($k):$input[$k]} feels especially clunky...) and that this is a chance for me to learn. jq -n '{"1":"a","2":"b","3":"c"}' \ | jq --arg keys '["1","3","4"]' \ '. as $input | ( $keys | fromjson ) | map( . as $k | $input | select(has($k)) | {($k):$input[$k]} ) | add' Any ideas how to clean this

Can I define an enum as a subset of another enum's cases?

风格不统一 提交于 2019-12-10 03:32:00
问题 Note: This is basically the same question as another one I've posted on Stackoverflow yesterday. However, I figured that I used a poor example in that question that didn't quite boil it down to the essence of what I had in mind. As all replies to that original post refer to that first question I thought it might be a better idea to put the new example in a separate question — no duplication intended. Model Game Characters That Can Move Let's define an enum of directions for use in a simple

How to subset consecutive rows if they meet a condition

邮差的信 提交于 2019-12-10 03:28:45
问题 I am using R to analyze a number of time series (1951-2013) containing daily values of Max and Min temperatures. The data has the following structure: YEAR MONTH DAY MAX MIN 1985 1 1 22.8 9.4 1985 1 2 28.6 11.7 1985 1 3 24.7 12.2 1985 1 4 17.2 8.0 1985 1 5 17.9 7.6 1985 1 6 17.7 8.1 I need to find the frequency of heat waves based on this definition: A period of three or more consecutive days ‎with a daily maximum and minimum temperature exceeding the 90th percentile of the maximum ‎and