subset

find all k-length subsets of list in prolog

ぐ巨炮叔叔 提交于 2019-12-04 04:03:27
问题 i need to find a k-length subset of list in prolog, i have this function: subset([], []). subset([E|Tail], [E|NTail]):- subset(Tail, NTail). subset([_|Tail], NTail):- subset(Tail, NTail). and i apply another rule for the length of the list, length(Xs,Size) the problem is it is very slow because it search for all-length subset, is there a direct recursive definition for this k-length subset? i searched for it for a week and cant find anything 回答1: Using your initial solution to subset/2 , you

template function with corresponding parameters to subset of tuple types

余生长醉 提交于 2019-12-04 02:39:52
I would like to write function as this find : multi_set<int, string, double, myType> m; //vector of tuples m.insert(/*some data*/); m.find<1,2>("something",2.123); Or m.find<0,3>(1,instanceOfMyType); m.find<1>("somethingelse"); Where find can be parametrized corresponding to any subset of tuple parameters. My code so far: template <typename ... T> class multi_set{ typedef tuple < T... > Tuple; vector<tuple<T...>> data = vector<tuple<T...>>(); public: void insert(T... t){ data.push_back(tuple<T...>(t...)); } template<size_t ... Pos> void find(???){ // then I would like to use those params to

Subset columns based on list of column names and bring the column before it

早过忘川 提交于 2019-12-04 02:22:23
I have a larger dataset following the same order, a unique date column, data, unique date column, date, etc. I am trying to subset not just the data column by name but the unique date column also. The code below selects columns based on a list of names, which is part of what I want but any ideas of how I can grab the column immediately before the subsetted column also? Looking to end up with a DF containing Date1, Fire, Date3, Earth columns (using just the NameList). Here is my reproducible code: Cnames <- c("Date1","Fire","Date2","Water","Date3","Earth") MAINDF <- data.frame(replicate(6,runif

Consistent formulations of sets in Coq?

此生再无相见时 提交于 2019-12-04 02:06:14
I'm quite new at Coq and trying to develop a framework based on my research. My work is quite definition-heavy and I'm having trouble encoding it because of how Coq seems to treat sets. There are Type and Set , which they call 'sorts', and I can use them to define a new set: Variable X: Type. And then there's a library encoding (sub)sets as ' Ensembles ', which are functions from some Type to a Prop . In other words, they are predicates on a Type : Variable Y: Ensemble X. Ensemble s feel more like proper mathematical sets. Plus, they are built upon by many other libraries. I've tried focussing

Repeat a subsetting function by adding a new subsetting variable at each round in R

丶灬走出姿态 提交于 2019-12-04 02:00:32
问题 I have a function ( foo ) to subset any variable from the list L . It works perfect! But can I by default add variable weeks to whatever variable being subsetted? For example, suppose I want to subset type == 1 , can I also by default add all unique values of weeks (in my data weeks has 3 unique values excluding NA ) to that in a looped fashion: type==1 & weeks==1 (Round 1) ; type==1 & weeks==2 (Round 2) ; type==1 & weeks==3 (Round 3) foo <- function(List, what){ s <- substitute(what) h <-

subset inside a function by the variables specified in ddply

折月煮酒 提交于 2019-12-04 01:38:51
问题 Often I need to subset a data.frame inside a function by the variables that I am subsetting another data.frame to which I apply ddply. To do that I explicitly write again the variables inside the function and I wonder whether there is a more elegant way to do that. Below I include a trivial example just to show which is my current approach to do this. d1<-expand.grid(x=c('a','b'),y=c('c','d'),z=1:3) d2<-expand.grid(x=c('a','b'),y=c('c','d'),z=4:6) results<-ddply(d1,.(x,y),function(d) { d2Sub<

Subset by multiple conditions

依然范特西╮ 提交于 2019-12-04 01:13:23
问题 Maybe it's something basic, but I couldn't find the answer. I have Id Year V1 1 2009 33 1 2010 67 1 2011 38 2 2009 45 3 2009 65 3 2010 74 4 2009 47 4 2010 51 4 2011 14 I need to select only the rows that have the same Id but it´s in the three years 2009, 2010 and 2011. Id Year V1 1 2009 33 1 2010 67 1 2011 38 4 2009 47 4 2010 51 4 2011 14 I try d1_3 <- subset(d1, Year==2009 |Year==2010 |Year==2011 ) but it doesn't work. Can anyone provide some suggestions that how I can do this in R? 回答1: I

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

主宰稳场 提交于 2019-12-04 00:44:02
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 patients with a class value of 1. In the past I have used the subset function to select rows based on

Subset data table without using <-

流过昼夜 提交于 2019-12-04 00:40:55
I want to subset some rows of a data table. Like this: # load data data("mtcars") # convert to data table setDT(mtcars,keep.rownames = T) # Subset data mtcars <- mtcars[like(rn,"Mer"),] # or mtcars <- mtcars[mpg > 20,] However, I'm working with a huge data set and I wanted to avoid using <- , which is not memory efficient because it makes a copy of the data. Is this correct? Is it possible to update the filtered data without <- ? What you are asking would be delete rows by reference . It is not yet possible, but there is FR for that #635 . Until then you need to copy (in-memory) your data

How to select some rows with specific rownames from a dataframe? [closed]

人走茶凉 提交于 2019-12-03 23:34:44
Closed. This question is off-topic. It is not currently accepting answers. Learn more . Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I have a data frame with several rows. I want to select some rows with specific rownames (such as stu2,stu3,stu5,stu9 ) from this dataframe. The input example dataframe is as follows: attr1 attr2 attr3 attr4 stu1 0 0 1 0 stu2 -1 1 -1 1 stu3 1 -1 0 -1 stu4 1 -1 1 -1 stu5 -1 1 0 1 stu6 1 -1 1 0 stu7 -1 -1 -1 1 stu8 1 -1 0 -1 stu9 -1 -1 1 -1 stu10 -1 1 0 1 Expected output: attr1 attr2 attr3 attr4 stu2