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
3 answers

Selecting rows by offsetting

I have this data frame, lets call it my_df. It looks like this: my_df <- data.frame(rnorm(n = 30,sd=.5),rep(c("a","b","c"),each=10)) names(my_df) <- c("num","let") head(my_df) num let 1 0.01202600 a 2 1.09025768 a 3 -0.08656178 …
Chase Grimm
  • 417
  • 3
  • 14
2
votes
1 answer

(R) [] / subset() returns an empty data frame

I have a large dataset that looks something like this with a few hundred thousand more entries, saved as data: Group1 dtm_Flight_Date Departure Arrival str_Fare_Category_Ident 1 8P104 06/11/2010 9:05 YYJ …
Jon
  • 51
  • 7
2
votes
1 answer

Slicing rows of pandas dataframe between

I have a pandas dataframe with a column that marks interesting points of data in another column (e.g. the locations of peaks and troughs). I often need to do some computation on the values between each marker. Is there a neat way to slice the…
Tom
  • 61
  • 6
2
votes
2 answers

R dplyr - error in subsetting of local data frame

As part of a larger and more complex body of code, I am running into a dplyr / local data frame challenge. As the simplified example per below shows, the code includes a basic type of subsetting that works in base R: #creation of data…
user1885116
  • 1,757
  • 4
  • 26
  • 39
2
votes
1 answer

subset=.() cannot be called in ggplot() directly

It is pretty clear what the following line wants to do: ggplot(data=mtcars, aes(x=mpg, y=cyl), subset=.(gear=="5")) + geom_point(aes(colour=gear)) But it doesn't work (subset is just ignored). What does indeed work is: ggplot(data=mtcars,…
AF7
  • 3,160
  • 28
  • 63
2
votes
5 answers

How to get subset of two arrays into a different array using javascript?

i have 2 arrays. arr1=[1,8,1,3,2] arr2=[3,8,1] I want to put elements [8,1] subset into arr3. How can i do this using javascript?I used the following code. But doesn't seemed to be working. function subsetFind() { var arr1 =…
Tharu
  • 353
  • 1
  • 2
  • 11
2
votes
1 answer

R, create a new sorted dataframe with use of dplyr?

i am new to R and a bit overwhelmed by an assignment. i am asked to create a new dataframe out of an existing one ( the diamonds data that come preinstalled with ggplot2). The dataframe should look as follows: mean_price median_price min_price…
hmmmbob
  • 1,167
  • 5
  • 19
  • 33
2
votes
1 answer

How to assign values to a column for a subset of data frame rows

I have a large data frame and I am trying to assign values to a particular data column for specific subsets. subset(P2Y12R_binding_summary,(SYSTEM=="4NTJ")&(VARIANT=="D294N")) SYSTEM VARIANT MODEL EPSIN INP dE_water_free dE_ERR_water_free…
wmsmith
  • 542
  • 4
  • 15
2
votes
2 answers

Finding a mean value of velocity by month (using R)

I have data table here: row V1 velocity 1 2009-04-06 95.9230769230769 2 2009-04-11 95.0985074626866 3 2009-04-17 95.8064935064935 4 2009-04-22 94.6357142857143 5 2009-04-27 95.3626865671642 6 2009-05-03 …
jamryu
  • 668
  • 10
  • 24
2
votes
3 answers

Average a subset of a matrix in a loop in matlab

I work with an image that I consider as a matrix. I want to turn a 800 x 800 matrix (A) into a 400 x 400 matrix (B) where the mean of 4 cells of the A matrix = 1 cell of the B matrix (I know this not a right code line) : B[1,1] =mean2(A[1,1 + 1,2 +…
Sarahdata
  • 309
  • 3
  • 15
2
votes
1 answer

removing and aggregating duplicates

I've posted a sample of the data I'm working with here. "Parcel.." is the main indexing variable and there are good amount of duplicates. The duplicates are not consistent in all of the other columns. My goal is to aggregate the data set so that…
slap-a-da-bias
  • 376
  • 1
  • 6
  • 25
2
votes
3 answers

Subset duplicate values with two different status values

I have Id Values some are duplicates, there is another column Status (yes/No) , I want to extract the subset of duplicate values which have two different status values. For example , if my dataset is as below Id Status 23984 Yes …
2
votes
4 answers

Filtering a Dataset by another Dataset in R

The task I am trying to accomplish is essentially filtering one dataset by the entries in another dataset by entries in an "id" column. The data sets I am working with are quite large having 10 of thousands of entries and 30 or so variables. I have…
SnakeSnake
  • 23
  • 1
  • 1
  • 4
2
votes
2 answers

taking some values from a column to make multiple new columns matched by an id column in R

I have two data frames in R: df1 Site_code Species_code Abundance 1 MRN 50 1 TFP 100 2 MRN 5 2 XNP 20 2 AMP 15 and in df2 I…
Frieda
  • 65
  • 6
2
votes
1 answer

Getting specific rows according to a subset in R

I've been trying for hours with this one. I have a dataset with two columns, let's call them V1 and V2.I also have a list of imporatant V1 values - Vx. I managed to acquire a subset of V1 with intersect function, so: intersect <-…
sdgaw erzswer
  • 2,182
  • 2
  • 26
  • 45
1 2 3
99
100