subset

How to iteratively generate k elements subsets from a set of size n in java?

孤街浪徒 提交于 2019-11-27 01:58:10
I'm working on a puzzle that involves analyzing all size k subsets and figuring out which one is optimal. I wrote a solution that works when the number of subsets is small, but it runs out of memory for larger problems. Now I'm trying to translate an iterative function written in python to java so that I can analyze each subset as it's created and get only the value that represents how optimized it is and not the entire set so that I won't run out of memory. Here is what I have so far and it doesn't seem to finish even for very small problems: public static LinkedList<LinkedList<Integer>>

subsetting in data.table

孤者浪人 提交于 2019-11-27 01:36:33
问题 I am trying to subset a data.table ( from the package data.table ) in R (not a data.frame). I have a 4 digit year as a key. I would like to subset by taking a series of years. For example, I want to pull all the records that are from 1999, 2000, 2001. I have tried passing in my DT[J(year)] binary search syntax the following: 1999,2000,2001 c(1999,2000,2001) 1999, 2000, 2001 but none of these seem to work. Anyone know how to do a subset where the years you want to select are not just 1 but

How to find all subsets of a set in JavaScript?

自古美人都是妖i 提交于 2019-11-27 01:34:11
I need to get all possible subsets of an array. Say I have this: [1, 2, 3] How do I get this? [], [1], [2], [1, 2], [2, 3], [1, 3], [1, 2, 3] I am interested in all subsets. For subsets of specific length, refer to the following questions: Finding subsets of size n: 1 , 2 Finding subsets of size > 1: 1 Here is one more very elegant solution with no loops or recursion, only using the map and reduce array native functions. const getAllSubsets = theArray => theArray.reduce( (subsets, value) => subsets.concat( subsets.map(set => [value,...set]) ), [[]] ); console.log(getAllSubsets([1,2,3])); We

Using multiple criteria in subset function and logical operators

心已入冬 提交于 2019-11-27 01:28:43
If I want to select a subset of data in R, I can use the subset function. I wanted to base an analysis on data that that was matching one of a few criteria, e.g. that a certain variable was either 1, 2 or 3. I tried myNewDataFrame <- subset(bigfive, subset = (bigfive$bf11==(1||2||3))) It did always just select values that matched the first of the criteria, here 1. My assumption was that it would start with 1 and if it does evaluate to "false" it would go on to 2 and than to 3, and if none matches the statement after == is "false" and if one of them matches, it is "true". I got the right result

Subset data.frame by date

∥☆過路亽.° 提交于 2019-11-27 01:21:22
I have a dataset called EPL2011_12 . I would like to make new a dataset by subsetting the original by date. The dates are in the column named Date The dates are in DD-MM-YY format. I have tried EPL2011_12FirstHalf <- subset(EPL2011_12, Date > 13-01-12) and EPL2011_12FirstHalf <- subset(EPL2011_12, Date > "13-01-12") but get this error message each time. Warning message: In Ops.factor(Date, 13- 1 - 12) : > not meaningful for factors I guess that means R is treating like text instead of a number and that why it won't work? Well, it's clearly not a number since it has dashes in it. The error

How to remove rows of a matrix by row name, rather than numerical index?

妖精的绣舞 提交于 2019-11-27 01:15:33
问题 I have matrix g : > g[1:5,1:5] rs7510853 rs10154488 rs12159982 rs2844887 rs2844888 NA06985 "CC" "CC" "CC" "CC" "CC" NA06991 "CC" "CC" "CC" "CC" "CC" NA06993 "CC" "CC" "CC" "CC" "CC" NA06994 "CC" "CC" "CC" "CC" "CC" NA07000 "CC" "CC" "CC" "CC" "CC" > rownames(g)[1:2]->remove > remove [1] "NA06985" "NA06991" > g[-remove,] Error in -remove : invalid argument to unary operator Is there a simple way to do what I want to do here (remove the ID's referenced in the vector 'remove' from matrix g ?

Selecting columns in R data frame based on those *not* in a vector

坚强是说给别人听的谎言 提交于 2019-11-27 00:41:50
I'm familiar with being able to extract columns from an R data frame (or matrix) like so: df.2 <- df[, c("name1", "name2", "name3")] But can one use a ! or other tool to select all but those listed columns ? For background, I have a data frame with quite a few column vectors and I'd like to avoid: Typing out the majority of the names when I could just remove a minority Using the much shorter df.2 <- df[, c(1,3,5)] because when my .csv file changes, my code goes to heck since the numbering isn't the same anymore. I'm new to R and think I've learned the hard way not to use number vectors for

Python: Check if one dictionary is a subset of another larger dictionary

☆樱花仙子☆ 提交于 2019-11-27 00:15:49
问题 I'm trying to write a custom filter method that takes an arbitrary number of kwargs and returns a list containing the elements of a database-like list that contain those kwargs . For example, suppose d1 = {'a':'2', 'b':'3'} and d2 = the same thing. d1 == d2 results in True. But suppose d2 = the same thing plus a bunch of other things. My method needs to be able to tell if d1 in d2 , but Python can't do that with dictionaries. Context: I have a Word class, and each object has properties like

Subset data frame to include only levels of one factor that have values in both levels of another factor

早过忘川 提交于 2019-11-26 23:32:14
问题 I am working with a data frame that deals with numeric measurements. Some individuals have been measured several times, both as juveniles and adults. A reproducible example: ID <- c("a1", "a2", "a3", "a4", "a1", "a2", "a5", "a6", "a1", "a3") age <- rep(c("juvenile", "adult"), each=5) size <- rnorm(10) # e.g. a1 is measured 3 times, twice as a juvenile, once as an adult. d <- data.frame(ID, age, size) My goal is to subset that data frame by selecting the IDs that appear at least once as a

R gotcha: logical-and operator for combining conditions is & not &&

不想你离开。 提交于 2019-11-26 22:40:18
Why doesn't subset() work with a logical and && operator combining two conditions? > subset(tt, (customer_id==177 && visit_date=="2010-08-26")) <0 rows> (or 0-length row.names) but they each work individually: > subset(tt, customer_id==177) > subset(tt, visit_date=="2010-08-26") (Want to avoid using large temporary variables - my dataset is huge) From the help page for Logical Operators , accessible by ?"&&" : & and && indicate logical AND and | and || indicate logical OR. The shorter form performs elementwise comparisons in much the same way as arithmetic operators. The longer form evaluates