subset

R: loop through data frame extracting subset of data depending on date

落爺英雄遲暮 提交于 2019-12-03 13:36:58
问题 I have a large data frame that consists of data that looks something like this: date w x y z region 1 2012 01 21 43 12 3 NORTH 2 2012 02 32 54 21 16 NORTH 3 2012 03 14 32 65 32 NORTH 4 2012 04 65 33 75 21 NORTH : : : : : : : : : : : : : : 12 2012 12 32 58 53 17 NORTH 13 2012 01 12 47 43 23 SOUTH 14 2012 02 87 43 21 76 SOUTH : : : : : : : 25 2012 01 12 46 84 29 EAST 26 2012 02 85 29 90 12 EAST : : : : : : : : : : : : : : I want to extract section of the data that have the same date value, for

subset() of a vector in R

强颜欢笑 提交于 2019-12-03 13:31:37
问题 I've written the following function based on subset() , which I find handy: ss <- function (x, subset, ...) { r <- eval(substitute(subset), data.frame(.=x), parent.frame()) if (!is.logical(r)) stop("'subset' must be logical") x[r & !is.na(r)] } So, I can write: ss(myDataFrame$MyVariableName, 500 < . & . < 1500) instead of myDataFrame$MyVariableName[ 500 < myDataFrame$MyVariableName & myDataFrame$MyVariableName < 1500] This seems like something other people might have developed solutions for,

Power set generated by bits

我们两清 提交于 2019-12-03 11:33:28
问题 I have this code which generates power set of an array of size 4 (number is just example, less combinations to write...). #define ARRAY_SIZE 4 unsigned int i, j, bits, i_max = 1U << ARRAY_SIZE; int array[ARRAY_SIZE]; for (i = 0; i < i_max ; ++i) { for (bits = i, j = 0; bits; bits >>= 1, ++j) { if (bits & 1) printf("%d", array[j]); } } Output: {} {1} {2} {1, 2} {3} {1, 3} {2, 3} {1, 2, 3} {4} {1, 4} {2, 4} {1, 2, 4} {3, 4} {1, 3, 4} {2, 3, 4} {1, 2, 3, 4} I need that output to be like this one

How do I check if one vector is a subset of another?

你离开我真会死。 提交于 2019-12-03 10:44:26
Currently, I think my best option is to use std::set_intersection, and then check if the size of the smaller input is the same as the number of elements filled by set_intersection. Is there a better solution? Klark Try this: if (std::includes(set_one.begin(), set_one.end(), set_two.begin(), set_two.end())) { // ... } About includes() . The includes() algorithm compares two sorted sequences and returns true if every element in the range [start2, finish2) is contained in the range [start1, finish1). It returns false otherwise. includes() assumes that the sequences are sorted using operator<(),

Using attributes of `ftable` for extracting data

时间秒杀一切 提交于 2019-12-03 10:02:45
I sometimes use the ftable function purely for its presentation of hierarchical categories. However, sometimes, when the table is large, I would like to further subset the table before using it. Let's say we're starting with: mytable <- ftable(Titanic, row.vars = 1:3) mytable ## Survived No Yes ## Class Sex Age ## 1st Male Child 0 5 ## Adult 118 57 ## Female Child 0 1 ## Adult 4 140 ## 2nd Male Child 0 11 ## Adult 154 14 ## Female Child 0 13 ## Adult 13 80 ## 3rd Male Child 35 13 ## Adult 387 75 ## Female Child 17 14 ## Adult 89 76 ## Crew Male Child 0 0 ## Adult 670 192 ## Female Child 0 0 ##

How to verify that one XSD schema is a subset of another XSD schema?

混江龙づ霸主 提交于 2019-12-03 09:45:10
问题 How can I verify that one XSD schema is a subset of another XSD schema? We are creating a system-of-systems application using a collection of "blueprint" XSD schemas (which defines all possible inputs or outputs available to a subcomponent). Many subcomponents are being implemented, and these subcomponents pass data among themselves using XML files. Each subcomponent creates a subset of the relevant blueprint XSD schema (to indicate which of the possible inputs or output it has chosen to

subset() drops attributes on vectors; how to maintain/persist them?

ぐ巨炮叔叔 提交于 2019-12-03 09:08:37
问题 Let's say I have a vector where I've set a few attributes: vec <- sample(50:100,1000, replace=TRUE) attr(vec, "someattr") <- "Hello World" When I subset the vector, the attributes are dropped. For example: tmp.vec <- vec[which(vec > 80)] attributes(tmp.vec) # Now NULL Is there a way to, subset and persist attributes without having to save them to another temporary object? Bonus: Where would one find documentation of this behaviour? 回答1: I would write a method for [ or subset() (depending on

Pandas: Use iterrows on Dataframe subset

有些话、适合烂在心里 提交于 2019-12-03 07:58:19
What is the best way to do iterrows with a subset of a DataFrame? Let's take the following simple example: import pandas as pd df = pd.DataFrame({ 'Product': list('AAAABBAA'), 'Quantity': [5,2,5,10,1,5,2,3], 'Start' : [ DT.datetime(2013,1,1,9,0), DT.datetime(2013,1,1,8,5), DT.datetime(2013,2,5,14,0), DT.datetime(2013,2,5,16,0), DT.datetime(2013,2,8,20,0), DT.datetime(2013,2,8,16,50), DT.datetime(2013,2,8,7,0), DT.datetime(2013,7,4,8,0)]}) df = df.set_index(['Start']) Now I would like to modify a subset of this DataFrame using the itterrows function, e.g.: for i, row_i in df[df.Product == 'A']

Efficient method to subset drop rows with NA values in R

点点圈 提交于 2019-12-03 07:46:07
问题 Background Before running a stepwise model selection, I need to remove missing values for any of my model terms. With quite a few terms in my model, there are therefore quite a few vectors that I need to look in for NA values (and drop any rows that have NA values in any of those vectors). However, there are also vectors that contain NA values that I do not want to use as terms / criteria for dropping rows. Question How do I drop rows from a dataframe which contain NA values for any of a list

Enumerate through a subset of a Collection in C#?

眉间皱痕 提交于 2019-12-03 07:00:27
Is there a good way to enumerate through only a subset of a Collection in C#? That is, I have a collection of a large number of objects (say, 1000), but I'd like to enumerate through only elements 250 - 340. Is there a good way to get an Enumerator for a subset of the collection, without using another Collection? Edit: should have mentioned that this is using .NET Framework 2.0. Try the following var col = GetTheCollection(); var subset = col.Skip(250).Take(90); Or more generally public static IEnumerable<T> GetRange(this IEnumerable<T> source, int start, int end) { // Error checking removed