Questions tagged [subset]

A subset consists of those elements selected from a larger set of elements, by their position in the larger set or other features, such as their value.

Definition:

From Wikipedia:

a set A is a subset of a set B, or equivalently B is a superset of A, if A is 'contained' inside B, that is, all elements of A are also elements of B.

Uses:

  • In , subset is a function that selects a subset of elements from a vector, matrix, or data frame, given some logical expression (caution: subset drops incomplete cases; see How to subset data in R without losing NA rows?). However, for programmatic use (as opposed to interactive use) it is better to use the \[ (or [[) operators or the filter function from dplyr. substring is used to find subsets of character strings.
  • In , a subset of an array can be obtained with array[indices].
6799 questions
2
votes
1 answer

R - How to choose rows based on values in column

I have a dataframe, data, shown below: head(data) code x y z new 1 123456 1 2 0 654321 2 999999 2 3 0 543210 3 000998 3 4 0 887765 4 106813 4…
Learning_R
  • 609
  • 1
  • 6
  • 11
2
votes
1 answer

all subsets with all elements of a list in prolog

I'm trying to compute a list of all subsets of a given list with all its elements, but so far I've only succeeded to find subsets of two elements, but this is not a right solution for my problem.. can anyone help me? I know that problems like this…
Nelly
  • 299
  • 3
  • 5
  • 16
2
votes
1 answer

Find the index of a list which is subset in a list of list

I have two very large list of list (order of 5 millions). For instance: 1) The first list, a, contains always list of 8 elements. 2) The second list, b, contains always list of 4 elements. For each list in b there may be more than one subsets but…
2
votes
1 answer

subset matrix based on cell values

This should be simple, but I cannot figure it out: I have a square matrix with integer values in each cell (result of an all vs all distance calculation). I would like to subset the matrix based on the cell values, e.g. cell == 8, or cell <= 6 ,…
Scott Presnell
  • 1,528
  • 10
  • 23
2
votes
1 answer

Find all disjoint subsets of a set, respecting the element order

Lets say I want to implement a solution in Python 2.7. I have a list of strings, e.g. A = ['AA', 'BB', 'CC', 'DD']. The desired output would be a set of disjoint subsets of A, e.g A_1, A_2 ... A_N, such that (A_1 U A_2 U ... U A_N) = A, (A_1 ∩ A_2…
El Brutale
  • 93
  • 8
2
votes
1 answer

All subsets from a set in python recursively (Nonetype error)

I am trying to get all subsets from a set recursively, here is the code I have so far: aset = [1,2,10,4,5,99] def subSets(aset): if len(aset) == 0: return [] prevSets = subSets(aset[:len(aset)-1]) newSets =[] print prevSets …
ApathyBear
  • 9,057
  • 14
  • 56
  • 90
2
votes
1 answer

Multiple subsets with unique counts and sums in R

I have a coding problem that is beyond my skill level. I am hoping that someone can help me by pointing me in the direction of the tools that I need to finish this task parsimoniously. I am trying to create a plot of the number of unique…
eyerah
  • 129
  • 1
  • 2
  • 7
2
votes
4 answers

Create column identifying minimum character from within a group and label ties

I have paired data for 10 subjects (with some missing and some ties). My goal is to select the eye with the best disc_grade (A > B > C) and label ties accordingly from the data frame below. I'm stuck on how to use R code to select the rows with…
user25494
  • 1,289
  • 14
  • 27
2
votes
2 answers

Nested subsetting with "["

I recently discovered that, after subsetting an object (i.e. a data frame) with "[", the resulting object could be subset with "[" on the same line of code (I should have realized it earlier!). Here is an example: # Create a data frame df1 <-…
SavedByJESUS
  • 3,262
  • 4
  • 32
  • 47
2
votes
3 answers

How to count the number of items in a subset group of an array that are greater than a specific value within that array?

I would like to count the number of items in a subset group of an array that are greater than a specific value within that array in R. See below example, for every year there is an external benchmark that is part of the given data (this is not the…
Martijn
  • 129
  • 3
  • 10
2
votes
1 answer

R - Remove records with question marks (or other characters)

I have a vector of over a million records, and some records have characters such as ?, *, & in them (the rest of the record entry is alphanumeric). I need to identify these records (according to the specific character--e.g., the question mark), and…
HAL-9000
  • 99
  • 2
  • 9
2
votes
3 answers

R: ifelse, return a subset based on a condition

I am still learning R and bumped into something that is beyond my comprehansion. I spent like 2 hours trying to figure it out on my own and failed :-( . I have a data.frame (let's think of iris, for instance) that I want to subset using ifelse. If…
rpl
  • 451
  • 4
  • 13
2
votes
2 answers

Eliminate dataframe rows that match a character string

I have a dataframe rawdata with columns that contain ecological information. I am trying to eliminate all of the rows for which the column LatinName matches a vector of species for which I already have some data, and create a new dataframe with only…
AFH
  • 665
  • 1
  • 9
  • 28
2
votes
1 answer

R: adding items in a list

dput(dat) list(structure(c(0, 0, -1, -2, -1, -2, -1, -2, 0, 2, 99, 0, -1, -2, -1, -2), .Dim = c(2L, 8L), .Dimnames = list(c("type1", "type2" ), c("A", "B", "C", "D", "E", "F", "G", "H"))), structure(c(1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 99, 0, 1, 3, 1,…
Adrian
  • 9,229
  • 24
  • 74
  • 132
2
votes
1 answer

R - Selecting elements from factors

If I have a dataframe as follows a b 1 5 red 2 11 red 3 7 red 4 1 red 5 3 green 6 8 green 7 12 green 8 6 green 9 2 blue 10 9 blue 11 10 blue 12 4 blue How can I select a certain element from each factor? For…
user3200293
  • 181
  • 5
  • 18