6,879 questions
0
votes
1
answer
37
views
Subset dataset by repeating temporal variable (accelerometer data) [duplicate]
I have a dataset from an accelerometer, which consists in a time variable and measurements in the 3 axis. I have 50 measurements per second, and my ultimate goal is to subset those measurements, i.e. ...
0
votes
0
answers
50
views
Removing rows from dataset based on how it relates to previous row in R [duplicate]
I am working with a large dataset of fish movement. Each row in the dataset represents a fish location with a particular timestamp, ID, etc. associated with that location. I have calculated distances ...
0
votes
0
answers
59
views
Subset error after importing with readr ("arguments imply differing number of rows") in Quarto R chunk
I can't subset rows after importing a csv with readr::read_csv from a .qmd.
Data example
Create a file called BSI_test8.csv with these two rows:
id,data_collection_date,data_collection,...
7
votes
5
answers
184
views
Filter vector by proportion of negative values
I have a vector with ordered negative and positive values:
x <- c(-35, -30, -25, -20, -15, -10, -5, -2, -1, -0.5, 0, 5, 22, 77)
I need to filter the values in the vector by a certain proportion ...
0
votes
1
answer
15
views
subsetting withinin ggplot2 command
Sorry if there´s already a thread on this, but I could´t find ther solution for my problem with existing posts!
I try to create a barplot subsetting a large dataframe in the gplot2 code. This is a ...
0
votes
0
answers
25
views
Subsetting global data based on latitude and longitude resulting in "TypeError: only integer scalar arrays can be converted to a scalar index" [duplicate]
I have a atmospheric global data set of size 721, 1440 from a grib2 file. Y and X are lat and lon values. Gridded to 721, 1440 to match the data.
extent=[10.0, 350.0, -60.0, 60.0]
lat_bnds,lon_bnds=[...
0
votes
0
answers
17
views
Dynamic Programming Table Extension Causes Incorrect Results for Subset Sum Partition Problem
I'm working on a dynamic programming problem related to counting the number of ways to partition an array into two subsets such that the absolute difference between their sums is equal to a given ...
1
vote
2
answers
73
views
Subsetting a custom time range in base R
I need to get the list of temperatures from a weather station from 9am to 9am the next day in R and set their dates to the second day. A simplified version of the data looks like
DateTime
Temp
2024-...
0
votes
0
answers
22
views
Generalizing the Subset Sum Problem to Finding Matching Subsets from Two Arrays
How can the subset sum problem, where the sum of n specific values equals a given number, be generalized to include arrays containing multiple elements?
Specifically, the subset sum problem involves ...
0
votes
1
answer
210
views
Complex subsetting in R for case-control study
I am trying to perform a complex subsetting of data in R. I work in epidemiology on cohort studies and I need to run some simulations to show performances of nested case-control designs.
In order to ...
13
votes
6
answers
2k
views
Is there a fast/clever way to return a logical vector if elements of a vector are in at least one interval?
Assume you have vector numeric vector x and a data frame df with columns start and stop. Is there a clever way to return a logical vector with length equal to x indicating if x is in at least one ...
0
votes
0
answers
27
views
Problems with subsetting data in R [duplicate]
I'm trying to calculate group mean for year-skilled groups, but all unskilled values turn to be NAN. There are obs with skilled==1 and skilled==0 every year.
Below are my code:
wage_df <- df %>% ...
0
votes
3
answers
81
views
How to subset R dataframe based on specific values in several columns?
I would like to subset an R dataframe to display all the rows that contain specific values that could be sitting in two or more columns. Suppose I've got dataframe df
HomeTeam AwayTeam
1 ...
2
votes
1
answer
130
views
Fast retrieval of all subsets of an arbitrary set from a list of sets in R
Is there a way of doing fast retrieval of all strict subsets of a set over a list (e.g. subsets binary encoded as a matrix where each row represents a subset) in R? I think a tree would suffice, but I ...
0
votes
2
answers
54
views
How to subset list of Dfs based on the string content of a specific column - R Language
Imagine I have the followuing list of Data Frames:
df1 <- data.frame (x = c(1, 2, 3), y = c(12, 11, 10), text = c("banana", "avocado", "letuce"))
df2 <- data.frame (...
1
vote
1
answer
46
views
Exclude interpolated rows where gap is bigger than a given theshhold
I have temperture data from different places. Recordings are usually made every hour but sometimes there are bigger gaps between two dates. So the data is like this:
df <- data.frame(date= ...
0
votes
0
answers
40
views
Aproximation Algorithim for Max Subset Problem
I'm looking for an approximation approach to what I am assuming is an NP hard problem. Given a list of sets F = {S1,...,Sm) that contain at most n elements from (0,...,n-1): what is the largest subset ...
0
votes
0
answers
20
views
How to Subtotal by year and by country in R [duplicate]
I am trying to subtotal net worth for billionaires by country and by year. I can get R to do it for one, but not both (I can either 'group_by' and sum by year or by country). But I cannot figure out ...
0
votes
1
answer
42
views
Create a subset dataframe when values in one dataframe match a condition of a defined value in another dataframe in R
I'm trying to create a subset dataframe (df3) when value of 1 in col1 (df1) matches value of 1 in signal (df2) at the same timestamp (datetime). The new dataframe should include datetime, col1 and ...
1
vote
1
answer
70
views
Trim a data frame from the top or bottom, according to a column with NAs
I have a data frame similar to final_df below, which I obtain like this:
datadf <- data.frame(time=1:100, A=rnorm(100), B=rnorm(100), C=rnorm(100))
datadf <- as.data.frame(tidyr::pivot_longer(...
1
vote
2
answers
80
views
How to create a subset of multiple data frames in a list that only contains the rows that have consecutive numbers in one of the columns?
I have a list of data frames that each have year, month, day, and temperature columns along with some other stuff. I have already figured out (with stack overflow help thanks guys) how to subset the ...
0
votes
1
answer
80
views
Finding maximum value of all possible subsets XOR's if the subsets can be infinitely generated
I wanted to solve this problem: C. Vampiric Powers, anyone?, Codeforces
In short, there is sequence a, and infinitely times we can find XOR of any subset and append the XOR of this subset to the end ...
2
votes
2
answers
72
views
Subsetting lists in R to get longest list
I have a list with items with varying numbers of elements, many of which are subsets of each other. I would like to remove all the items whose complete set of elements exist in other items
So for ...
0
votes
0
answers
9
views
Select data after a set of data sequence
London
Chocolate 7 12/6/2023
Vanila 6 11/6/2023
Rose 5 10/6/2023
California
Chocolate 7 11/5/2024
Vanila 6 10/5/2024
Rose 5 09/5/2024
I would like to pull all data after the ...
5
votes
5
answers
120
views
Replace set of words with another set of words in R
It is a simple question. I have a list of country names. However, I wanted to change few names with correct names. So, I have two more vectors; one with names to be changed, and second with correct ...
-1
votes
5
answers
66
views
Focusing on an element of a subset, of a subset
Fairly new to coding and I have a question regarding list and subsets.
Suppose this is my list:
list =
[[[a,2], [c,3], [e,3]],
[[g,4], [i,4] [k,3]],
[[b,3], [d,2], [f,2]]]
How would I go about making ...
0
votes
1
answer
69
views
Sampling in python with multiple conditions and percentages
Person ID
Condition 1
Condition 2
Condition 3
A
Yes
No
Yes
B
No
Yes
No
C
Yes
No
No
Hi! I have to generate a sample from a fairly large dataset, and the inclusion criteria are a little more ...
0
votes
2
answers
33
views
Merge two datasets in a many to one framework, where dataset B's columns are a subset of dataset A's
My dataset A is a panel of individuals, as below. Many individuals can belong to a single family (variable fam_id). I have person variables and family variables in this dataset. As you can see, I have ...
0
votes
0
answers
29
views
How to request a huge amount of select CJK characters from Google Fonts API?
I'm trying to figure out how to subset a Japanese font by simply using a Google Fonts API request. There seem to be two options: subset= and text=. However, the former requires a set name which seems ...
1
vote
2
answers
47
views
How to get column-wise summary statistics with missing codes?
I have written a custom function ord_table() to extract summary statistics from a series of databases. To get those summary statistics, I have to filter out missing data codes (all codes are large ...
1
vote
2
answers
67
views
How to create a mask based on points coordinates?
Starting from this situation:
I would like to create a boolean mask where all external points are considered as True while all internal point are False. Something like this :
The objective would be ...
1
vote
3
answers
117
views
Can we retrieve entries from a tibble using index matrix?
I have a matrix where the row and column indices are stored that I want to retrieve from a dataset. With a data.frame this works fine:
set.seed(1)
df <- data.frame(a= letters[1:10], b= LETTERS[1:10]...
-2
votes
3
answers
162
views
Is there a Numpy function to subset an array based on values (not indices) in a slice or range?
I am trying to extract, from an array, all values within a certain slice (something like a range, but with optional start, stop and step). And in that, I want to benefit from the heavy optimizations ...
0
votes
2
answers
36
views
Loop in r with subset makes incomplete selection
I have a data frame (words) containing words with five letters, in which each letter appears in one of five columns. The sixth column represents the log probability of the word based on letter ...
2
votes
2
answers
107
views
How to check if some number can be retrieved as the result of the summation or difference of the given numbers
I have an arbitrary list of positive integers and some number X. I want to check if it is possible to retrieve X using basic operations such as summation and difference.
Any number from the list can ...
0
votes
0
answers
22
views
find-if-array-can-be-divided-into-two-subsets-of-equal-sum-if-any-one-element-deleted
Given a array of numbers find if there is a way to delete/remove a number from the array and make one partition in the array( dividing the array into two subsets ) such that sum of elements in ...
1
vote
2
answers
71
views
How to remove all rows where at least one column does not have a value of 1?
I have a presence/absence matrix of species occurences, which looks like this:
coords.x coords.y 1 2 3
Point 1 -69.07354 -15.76097 0 NA NA
Point 2 -69....
-2
votes
1
answer
87
views
What is the use of creating a copy of the input in a recursive call?
This is a code to generate all the substrings in of a given vector
class Solution {
public:
void sub(vector<int> &ip, vector<int> &op, vector<vector<int>> &ans) ...
0
votes
1
answer
22
views
Why does passing by reference change the answer while producing unique subsets?
Here is a solution to a problem to generate unique subsets of an array nums:
#include <bits/stdc++.h>
using namespace std;
void solveRec(vector<int> ss, set<vector<int>> &...
0
votes
2
answers
61
views
Filtering my data frame is erasing my data frame despite correct number of rows
I have a dataframe of transactions (roughly 76K rows). Each row has a column called START_DATE which is when the transaction started.
I am trying to filter down to transactions with START_DATE > 1/...
1
vote
1
answer
102
views
Overriding the subset method in R for a specific class interferes with other objects
I am working with R and I have created a new subset method for objects of class new_object. Here is my function:
setGeneric('subset', function(x, i) standardGeneric('subset'))
setMethod('subset', '...
1
vote
1
answer
86
views
Compute largest subset of a set such that all the elements of the subset would pairwise respect a certain condition
I have a set S consisting of natural numbers and a function that when given two natural numbers as an input it returns either true or false. Let's call the criteria based on which it computes the ...
3
votes
3
answers
58
views
How to filter out numbers with n digits in a dataframe in R?
In my DATA below, I'm trying to subset()/dplyr::filter() the INs that are 5 digits long.
I'm using the following without success. Is there a better solution?
Tried: subset(DATA, nchar(sub('\\.[0-9]+', ...
0
votes
1
answer
25
views
How do I turn the values in a subset into text so that I can generate a wordcloud?
From a large tabular data set (using read.csv function) I have created a subset from a column that lists different job roles in the rows.
View(jobs_mysubset)
.....
\[995\] physician
\[996\] painter
...
1
vote
2
answers
48
views
Filter rows in an R tidy data frame based on same-column values that are located in different rows
I am trying to filter out the species (ASV) in samples that have lower abundance counts than the same species in controls. Below is a simplified version of my tidy data table:
ASV
ID
Type
Batch
...
1
vote
2
answers
51
views
how filter a dataframe to remove rows in which no column contains a value higher than X or lower than Y
I am trying to remove any rows of data that do not contain any values that are greater than 5 or less than -5 in order to exclude them from my data analysis. I could not find a way to use an OR ...
0
votes
1
answer
85
views
dataframe how to get subset of rows in a dataframe
I have the following code:
import yfinance as yf
stocks1 = ['AAL','AAPL','ABBV']
new_df1 = yf.download(tickers=stocks1,
start='2023-10-01',
end='2023-10-10')
...
1
vote
1
answer
40
views
Creating a subset that only includes columns that have a certain value in a certain vector
Input:
library(ISLR)
data("NCI60")
cancers <- NCI60$labs
gene_counts <- table(cancers)
g3 <- names(gene_counts[gene_counts > 3])
g3
subset_NCI60 <- NCI60[cancers %in% g3]
...
1
vote
1
answer
39
views
Indexing array with subset of argsorted indices
I'm trying to write a decision tree learner in numpy. For this, the x values need to be sorted once only and after that i should be able to reuse them.
For this, I have a 2d array of features x, of ...
0
votes
2
answers
58
views
Subsetting dataframe so as to retain combinations that contain all values for a certain variable in R [closed]
Let us generate the dataframe we want to subset
vDates =
seq(
from = as.Date("2024-01-01"),
to = as.Date("2024-01-5"),
by = 1
)
vToy = c(1, 2, 3)
vColors = c("...