subset

Coq case analysis and rewrite with function returning subset types

こ雲淡風輕ζ 提交于 2020-01-02 07:13:24
问题 I was working is this simple exercise about writing certified function using subset types. The idea is to first write a predecessor function pred : forall (n : {n : nat | n > 0}), {m : nat | S m = n.1}. and then using this definition give a funtion pred2 : forall (n : {n : nat | n > 1}), {m : nat | S (S m) = n.1}. I have no problem with the first one. Here is my code Program Definition pred (n : {n : nat | n > 0}) : {m : nat | S m = n.1} := match n with | O => _ | S n' => n' end. Next

Row-wise cor() on subset of columns using dplyr::mutate()

笑着哭i 提交于 2020-01-02 07:01:33
问题 set.seed(8) df <- data.frame( A=sample(c(1:3), 10, replace=T), B=sample(c(1:3), 10, replace=T), C=sample(c(1:3), 10, replace=T), D=sample(c(1:3), 10, replace=T), E=sample(c(1:3), 10, replace=T), F=sample(c(1:3), 10, replace=T)) Would like to pass a subset of columns into a dplyr mutate() and make a row-wise calculation, for instance cor() to get correlation between column A-C and D-F, but cannot figure out how. Found SO inspiration here, here and here, but nevertheless failed to produce an

Row-wise cor() on subset of columns using dplyr::mutate()

♀尐吖头ヾ 提交于 2020-01-02 07:01:09
问题 set.seed(8) df <- data.frame( A=sample(c(1:3), 10, replace=T), B=sample(c(1:3), 10, replace=T), C=sample(c(1:3), 10, replace=T), D=sample(c(1:3), 10, replace=T), E=sample(c(1:3), 10, replace=T), F=sample(c(1:3), 10, replace=T)) Would like to pass a subset of columns into a dplyr mutate() and make a row-wise calculation, for instance cor() to get correlation between column A-C and D-F, but cannot figure out how. Found SO inspiration here, here and here, but nevertheless failed to produce an

Check if list contains another list in R

走远了吗. 提交于 2020-01-02 02:35:11
问题 I want to check if a list (or a vector, equivalently) is contained into another one, not if it is a subset of its. Let us assume we have r <- c(1,1) s <- c(5,2) t <- c(1,2,5) The function should behave as follows: is.contained(r,t) [1] FALSE # as (1,1) is not contained in (1,2,5) since the former # contains two 1 whereas the latter only one. is.contained(s,t) [1] TRUE The operator %in% checks for subsets, hence it would return TRUE in both cases, likewise all or any . I am sure there is a one

How to find all subsets of a multiset that are in a given set?

一曲冷凌霜 提交于 2020-01-01 19:41:02
问题 Say I have a set D of multisets: D = { {d, g, o}, {a, e, t, t}, {a, m, t}, } Given a multiset M , like M = {a, a, m, t} I would like an algorithm f to give me all elements of D that are subsets (or more precisely, "submultisets") of M : f = {{a, m, t}} If we do only one such query, scanning over all elements of D (in O(#D) time) is clearly optimal. But if we want to answer many such queries for the same D and different M , we might be able to make it faster by preprocessing D into some

How to find all subsets of a multiset that are in a given set?

Deadly 提交于 2020-01-01 19:40:06
问题 Say I have a set D of multisets: D = { {d, g, o}, {a, e, t, t}, {a, m, t}, } Given a multiset M , like M = {a, a, m, t} I would like an algorithm f to give me all elements of D that are subsets (or more precisely, "submultisets") of M : f = {{a, m, t}} If we do only one such query, scanning over all elements of D (in O(#D) time) is clearly optimal. But if we want to answer many such queries for the same D and different M , we might be able to make it faster by preprocessing D into some

C# Check if a List is a part of another List [duplicate]

邮差的信 提交于 2020-01-01 11:45:00
问题 This question already has answers here : Check whether an array is a subset of another (8 answers) Closed 6 years ago . I have two lists as follows var query1 = from enrollments in db.Enrollments where enrollments.studentID == studentID && enrollments.result >= 50 && enrollments.enrolled == false select enrollments.subjectID; var query2 = from prerequisites in db.Prerequisites where prerequisites.subjectID == subjectID select prerequisites.prerequisiteID; Now I want to make sure that all the

R - How to make a subset of columns based on values in a row in a data frame

…衆ロ難τιáo~ 提交于 2020-01-01 08:19:09
问题 I have a matrix that I would like to subset and eventually use to make a plot. The data is a list of counts for specific blood markers for each patient in a population. It looks like this: df <- data.frame(MarkerID=c("Class","A123","A124"), MarkerName=c("","X","Y"), Patient.1=c(0,1,5), Patent.2=c(1,2,6), Patent.3=c(0,3,7), Patient.4=c(1,4,8)) I would like to make a data frame of all of the patients (columns 3-6) that have a class value of zero (1st row) and a second data frame of all of the

Subsetting in a second level R function

无人久伴 提交于 2020-01-01 05:45:14
问题 Function foo1 can subset a list by a requested variable (e.g., by = type == 1 ). Otherwise, foo1 will simply output the inputted list itself. For my purposes, I need to use foo1 within a new function called foo2 . In my code below, my desired output is obtained like so: foo2(data = D, by = G[[1]]) ; foo2(data = D, by = G[[2]]) ; foo2(data = D, by = G[[3]]) . But, I wonder why when I loop over G using lapply , I get an error as shown below ? foo1 <- function(data, by){ L <- split(data, data

Ordered subsets test

a 夏天 提交于 2020-01-01 05:42:06
问题 I want to test if an ordered set is a subset of a bigger ordered set. I used tuples and itertools.combinations : def subset_test(a, b): return a in itertools.combinations(b, len(a)) For instance, >>> subset_test((0, 1, 2), (0, 3, 1, 4, 2)) True >>> subset_test((0, 1, 2), (0, 3, 2, 4, 1)) False It works, but is slow when I test big tuples. 回答1: You can simply use an iterator to keep track of the position in B >>> A = (0, 1, 2) >>> B = (0, 3, 1, 4, 2) >>> b_iter = iter(B) >>> all(a in b_iter