subset

Generate List with Combination of Subset of List, Java

廉价感情. 提交于 2019-12-02 14:44:39
问题 This question is to be implemented in Java. I have a class named Competitor, with Type, Name and Power. public class Competitor { private final int type; private final String name; private final int power; public Competitor(int type, String name, int power) { this.type = type; this.name = name; this.power = power; } public int getType() { return type; } public String getName() { return name; } public int getPower() { return power; } @Override public String toString() { return "Competitor{" +

In repeated measures data, how to subset to select matched cases and controls?

核能气质少年 提交于 2019-12-02 13:56:10
I have a set of data clustered by family, research question is do 2 people in the same family with different characteristic x have the same binary (yes/no) outcome y. In some families, all members are "yes" for y. In other families, some are "yes" and some are "no" for y. I want to get only the families with discordant outcome statuses. I am guessing the code will be some sort of conditional logic statements but can't quite figure it out yet... In the sample data below, for example, I only want to get families 2 and 3. Thank you for your help! #sample data df <- as.data.frame(cbind( famid <- c

checking for equality

旧城冷巷雨未停 提交于 2019-12-02 13:22:40
i want to check equality of a dataset. the data set is looking like this Equips <- c(1,1,1,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5,5,5,6,7,8) Notifs <- c(10,10,20,55,63,67,71,73,73,73,81,81,83,32,32,32,32, 47,48,45,45,45,51,51,55,56,69,65,88) Comps <- c("Motor","Ventil","Motor","Gehäuse","Ventil","Motor","Steuerung","Motor", "Ventil","Gehäuse","Gehäuse","Ventil","Motor","Schraube","Motor","Festplatte", "Heizgerät","Motor","Schraube","Schraube","Lichtmaschine","Bremse","Lichtmaschine", "Schraube","Lichtmaschine","Lichtmaschine","Motor","Ventil","Schraube") rank <- c(1,1,2,1,2,3,1,2,2,2,3,3,4

R: Subset / index an object by substring of the wanted entries

和自甴很熟 提交于 2019-12-02 13:12:02
问题 Is it possible to extract/subset a dataframe by indicating only a chunk of the wanted entries-string? The filter criteria is stored in an factor vector. But there are only the first three digits indicated. This should determine to subset all entries of the dataframe starting with them. Example: # Input dataframe data <- read.table(header=T, text=' ID sex size 0120010 M 7 0120020 F 6 0121031 F 9 0130010 M 11 0130020 M 11 0130030 F 14 0130040 M 11 0150030 F 11 0150110 F 12 0180030 F 9 1150110 F

Filtering a data frame in R and an unwanted filtered out result

纵然是瞬间 提交于 2019-12-02 12:42:21
问题 This snippet: names<-c("Alice","Bob","Charlie") ages<-c(25,24,25) friends<-data.frame(names,ages) a25 <- friends[friends$age==25,] a25 table(a25$names) gives me this output names ages 1 Alice 25 3 Charlie 25 Alice Bob Charlie 1 0 1 Now, why "Bob" is in the output since the data frame a25 does not include "Bob"? I would expected an output like this (from the table command): Alice Charlie 1 1 What am I missing? My environment: R version 2.15.2 (2012-10-26) Platform: i386-w64-mingw32/i386 (32

subsetting matrix with id from another matrix

时光怂恿深爱的人放手 提交于 2019-12-02 12:26:52
问题 I would like to subset the data of one matrix using data in a second matrix. The columns of one matrix is labeled. For example, area1 <- c(9836374,635440,23018,833696,936079,1472449,879042,220539,870581,217418,552303,269359,833696,936079,1472449,879042,220539,870581, 833696,936079,1472449,879042,220539,870581) id <- c(1,2,5,30,31,34,1,2,5,1,2,5,1,2,5,30,31,34,51,52,55,81,82,85) mat1 <- matrix(area1, ncol=3, byrow=T) mat2 <- matrix(id, ncol=3, byrow=T) dimnames(mat1) <-list(NULL, c("a1","a2",

Subsetting a data frame based on key spanning several columns in another (summary) data frame

放肆的年华 提交于 2019-12-02 11:56:51
问题 I have a data frame a with 4 identifying columns: A, B, C, D . A second data frame b , created with ddply() , contains a summary of all the values for different D s for every set of A,B,C . A third data frame c contains a subset of b with bad values that I want to delete from a . Thus, I want a subset from a , omitting all the rows identified by a combination of A,B,C that are also present in c . I can think of ways do this (ugly and inefficiently) in a loop, but, my DBA background encourages

subsetting a dataframe in R - unexpected results

大兔子大兔子 提交于 2019-12-02 11:26:00
问题 OK, couldn't find a better title Let's say I have my_dataframe: Name Value1 Value2 AA 10 20 BB 15 30 if I do: nrow(my_dataframe[my_dataframe$Value2>20,] I get '1' as result I want to create my_second_dataframe, such as there's only column 'Value2': my_second_dataframe<- my_dataframe[,'Value2', drop=FALSE] let me check it out: class(my_second_dataframe) [1] "data.frame" class(my_second_dataframe$Value2) [1] "numeric" but then: nrow(my_second_dataframe[my_second_dataframe$Value2>20,] NULL ?????

Selecting Specific Dates in R

无人久伴 提交于 2019-12-02 11:07:19
I am wondering how to create a subset of data in R based on a list of dates, rather than by a date range. For example, I have the following data set data which contains 3 years of 6-minute data. date zone month day year hour minute temp speed gust dir 1 09/06/2009 00:00 PDT 9 6 2009 0 0 62 2 15 156 2 09/06/2009 00:06 PDT 9 6 2009 0 6 62 13 16 157 I have used breeze<-subset(data, ws>=15 & wd>=247.5 & wd<=315, select=date:dir) to select the rows which meet my criteria for a sea breeze, which is fine, but what I want to do is create a subset of the days which contain those times that meet my

Generate subsets of length n

我们两清 提交于 2019-12-02 11:00:52
Given a Set , generate all subsets of length n. Sample input: set = new Set(['a', 'b', 'c']), length = 2 Sample output: Set {'a', 'b'}, Set {'a', 'c'}, Set {'b', 'c'} How to do this efficiently, without converting the Set to an Array ? I already have a good solution for arrays as input: function* subsets(array, length, start = 0) { if (start >= array.length || length < 1) { yield new Set(); } else { while (start <= array.length - length) { let first = array[start]; for (subset of subsets(array, length - 1, start + 1)) { subset.add(first); yield subset; } ++start; } } } let array = ['a', 'b',