subset

subset an additional variable and append it to the previous one in R

给你一囗甜甜゛ 提交于 2019-12-06 11:43:59
问题 I have a function that subset s what (i.e., a variable) user requests out of this dataset. The function works perfect. But I was wondering if there might be a way that in addition to what user requests, the function always subset entries that contain control == TRUE and append those to what the user has requested. For example, suppose user wants to subset entries with type == 4 . In this dataset, there are 4 such entries. As reproducible code and data below show, this is done easily BUT there

Conditional subsetting by POSIXct interval and another field containing interval

浪尽此生 提交于 2019-12-06 11:12:00
Given a dataset Dat where I have species (SP), Area (AR), and Time (TM) (in POSIXct). I want to subset the data for individuals that were present with Species A, within a half hour prior and after it was recorded, and within the same area, including two adjacent areas (+ and - 1). For example, if species A was present at 1:00 on area 4, I wish to subset all species present from 12:30 to 1:30 in the same day in areas 3,4 and 5. As an example: SP TM AR B 1-jan-03 07:22 1 F 1-jan-03 09:22 4 A 1-jan-03 09:22 1 C 1-jan-03 08:17 3 D 1-jan-03 09:20 1 E 1-jan-03 06:55 4 D 1-jan-03 09:03 1 E 1-jan-03

Subset Data for ggplot2 graph

淺唱寂寞╮ 提交于 2019-12-06 11:00:59
I am working with ggplot2 and have a question about how to subset data for plots. I have the following dataset (example) and need to create a line plot comparing Q1 data by year of Company A. x= 2015 Q1, 2016 Q1, 2017 Q1 y= Data for Company A Company Year Quarter Data A 2015 Q1 1 B 2015 Q1 2 C 2015 Q1 3 A 2015 Q2 4 B 2015 Q2 5 C 2015 Q2 6 A 2015 Q3 7 B 2015 Q3 8 C 2015 Q3 9 A 2016 Q1 10 B 2016 Q1 11 C 2016 Q1 12 A 2016 Q2 13 B 2016 Q2 14 C 2016 Q2 15 A 2016 Q3 17 B 2016 Q3 18 C 2016 Q3 19 For other graphs involved in this project I've been using this code: ggplot(df[df$Company=="A",], aes(x= ,

Using lapply and which to subset dataframe by both characteristic and fuction

一笑奈何 提交于 2019-12-06 10:31:20
I have a dataframe with 5 dimensions of data that looks like this: > dim(alldata) [1] 162 6 > head(alldata) value layer Kmultiplier Resolution Season Variable 1: 0.01308008 b .01K 1km Baseflow Evapotranspiration 2: 0.03974779 b .01K 1km Peak Flow Evapotranspiration 3: 0.02396524 b .01K 1km Summer Flow Evapotranspiration 4: -0.15670996 b .01K 1km Baseflow Discharge 5: 0.06774948 b .01K 1km Peak Flow Discharge 6: -0.04138313 b .01K 1km Summer Flow Discharge What I'd like to do is get the mean of the value column for certain 'characteristics' of the data based on the other columns. So I use which

mongodb - retrieve array subset

对着背影说爱祢 提交于 2019-12-06 10:28:52
what seemed a simple task, came to be a challenge for me. I have the following mongodb structure: { (...) "services": { "TCP80": { "data": [{ "status": 1, "delay": 3.87, "ts": 1308056460 },{ "status": 1, "delay": 2.83, "ts": 1308058080 },{ "status": 1, "delay": 5.77, "ts": 1308060720 }] } }} Now, the following query returns whole document: { 'services.TCP80.data.ts':{$gt:1308067020} } I wonder - is it possible for me to receive only those "data" array entries matching $gt criteria (kind of shrinked doc)? I was considering MapReduce, but could not locate even a single example on how to pass

Mapping MongoDB documents to case class with types but without embedded documents

被刻印的时光 ゝ 提交于 2019-12-06 08:22:22
问题 Subset looks like an interesting, thin MongoDB wrapper. In one of the examples given, there are Tweets and Users. However, User is a subdocument of Tweet . In classical SQL, this would be normalized into two separate tables with a foreign key from Tweet to User. In MongoDB, this wouldn't necessitate a DBRef , storing the user's ObjectId would be sufficient. Both in Subset and Salat this would result in these case classes: case class Tweet(_id: ObjectId, content: String, userId: ObjectId) case

Given an array, how to generate all combinations of subset size k?

江枫思渺然 提交于 2019-12-06 08:04:20
问题 So given input = [1, 2, 3] and k=2 this would return: 1 2 1 3 2 1 2 3 3 1 3 2 This is the closest to what I am looking for, but not quite: http://algorithms.tutorialhorizon.com/print-all-combinations-of-subset-of-size-k-from-given-array/ function subsetsOfSize(a, used, startIndex, currentSize, k) { if (currentSize === k) { for (var i = 0; i < a.length; i++) { if (used[i]) console.log(a[i]); } console.log('-'); return; } if (startIndex === a.length) return; used[startIndex] = true;

subset based on frequency level [duplicate]

情到浓时终转凉″ 提交于 2019-12-06 07:59:32
问题 This question already has answers here : Subset data frame based on number of rows per group (3 answers) Closed 2 years ago . I want to generate a df that selects rows associated with an "ID" that in turn is associated with a variable called cutoff. For this example, I set the cutoff to 9, meaning that I want to select rows in df1 whose ID value is associated with more than 9 rows. The last line of my code generates a df that I don't understand. The correct df would have 24 rows, all with

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

拜拜、爱过 提交于 2019-12-06 07:36:27
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} The question is not clear on the usage scope, but two calls to std::vector::erase would suffice and don't incur any reallocation. For your example: std::vector<int> testVec{1, 2, 3, 4, 5}; testVec

Analysis over time comparing 2 dataframes row by row

喜你入骨 提交于 2019-12-06 07:33:18
问题 This is a small portion of the dataframe I am working with for reference.I am working with a data frame (MG53_HanLab) in R that has a column for Time, several columns with the name "MG53" in them, several columns with the name "F2" and several with "Iono" in them. I would like to compare the means of each group for each time point. I understand that I have to subset the data and have tried doing control <- MG53_HanLab[c(2:11)] F2 <- MG53_HanLab[c(12:23)] iono <- MG53_HanLab[c(24:33)] which