subset

How do I check if one vector is a subset of another?

◇◆丶佛笑我妖孽 提交于 2019-12-21 03:32:53
问题 Currently, I think my best option is to use std::set_intersection, and then check if the size of the smaller input is the same as the number of elements filled by set_intersection. Is there a better solution? 回答1: Try this: if (std::includes(set_one.begin(), set_one.end(), set_two.begin(), set_two.end())) { // ... } About includes(). The includes() algorithm compares two sorted sequences and returns true if every element in the range [start2, finish2) is contained in the range [start1,

Filtering data in a dataframe based on criteria

ぃ、小莉子 提交于 2019-12-21 02:26:29
问题 I am new to R and can't get to grips with this concept. Suppose I have a table loaded called "places" with 3 say columns - city, population and average summer temperature Say I want to "filter" - produce a new table object where population is less than 1 million and average summer temperature is greater than 70 degrees. In any other program I have used this would be pretty easy but having done some research I'm working myself up into greater confusion. Given the purpose of R and what it does

How to take a subset from a netCDF file using latitude/longitude boundaries in R

放肆的年华 提交于 2019-12-20 19:41:12
问题 I have a netCDF file that I wish to extract a subset from defined by latitude/longitude boundaries (i.e. a lat/long defined box), using the ‘ncdf’ package in R. A summary of my netCDF file is below. It has two dimensions (latitude and longitude) and 1 variable (10U_GDS4_SFC). It is essentially a lat/long grid containing wind values: [1] "file example.nc has 2 dimensions:" [1] "lat_0 Size: 1280" [1] "lon_1 Size: 2560" [1] "------------------------" [1] "file example.nc has 1 variables:" [1]

R data.table join with inequality conditions

前提是你 提交于 2019-12-20 18:44:09
问题 I would like to subset my data based on multiple inequality conditions using the data.table package. The examples in the data.table manual show how to do this with character variables, but not with numeric inequalities. I also see how to do this using the subset function. But I really would like to take advantage of the data.table binary search speed. Below is an example of what I am trying to do. library(data.table) data <- data.table(X=seq(-5,5,1), Y=seq(-5,5,1), Z=seq(-5,5,1)) data setkey

Subset a file by row and column numbers

眉间皱痕 提交于 2019-12-20 09:53:20
问题 We want to subset a text file on rows and columns, where rows and columns numbers are read from a file. Excluding header (row 1) and rownames (col 1). inputFile.txt Tab delimited text file header 62 9 3 54 6 1 25 1 2 3 4 5 6 96 1 1 1 1 0 1 72 3 3 3 3 3 3 18 0 1 0 1 1 0 82 1 0 0 0 0 1 77 1 0 1 0 1 1 15 7 7 7 7 7 7 82 0 0 1 1 1 0 37 0 1 0 0 1 0 18 0 1 0 0 1 0 53 0 0 1 0 0 0 57 1 1 1 1 1 1 subsetCols.txt Comma separated with no spaces, one row, numbers ordered. In real data we have 500K columns,

Understanding .I in data.table in R

≡放荡痞女 提交于 2019-12-20 08:49:14
问题 I was playing around with data.table and I came across a distinction that I'm not sure I quite understand. Given the following dataset: library(data.table) set.seed(400) DT <- data.table(x = sample(LETTERS[1:5], 20, TRUE), key = "x"); DT Can you please explain to me the difference between the following expressions? 1) DT[J("E"), .I] 2) DT[ , .I[x == "E"] ] 3) DT[x == "E", .I] 回答1: set.seed(400) library(data.table) DT <- data.table(x = sample(LETTERS[1:5], 20, TRUE), key = "x"); DT 1) DT[ , .I

Subsetting list in R using double square brackets

懵懂的女人 提交于 2019-12-20 07:39:40
问题 After reading several threads about subsetting lists in R, I tried to fully grasp this notion by fooling around in Rstudio. I thought I understood the concept until I came across the following: x <- list(list(list(1), 2), list(list(list(3), 4), 5), 6) Why is it that x[[1]] returns a list with two elements and x[[1]][[1]] returns a list too? 回答1: Well, if you just write the definition of the list like this - x <- list( list( list(1), 2 ), list( list( list(3), 4 ), 5 ), 6 ) then it is easy to

Subsetting list in R using double square brackets

喜你入骨 提交于 2019-12-20 07:39:10
问题 After reading several threads about subsetting lists in R, I tried to fully grasp this notion by fooling around in Rstudio. I thought I understood the concept until I came across the following: x <- list(list(list(1), 2), list(list(list(3), 4), 5), 6) Why is it that x[[1]] returns a list with two elements and x[[1]][[1]] returns a list too? 回答1: Well, if you just write the definition of the list like this - x <- list( list( list(1), 2 ), list( list( list(3), 4 ), 5 ), 6 ) then it is easy to

Subset multiple rows with condition

∥☆過路亽.° 提交于 2019-12-20 06:44:21
问题 I have a .txt file read into a table called power with over 2 million observations of 9 variables. I am trying to subset power by two rows containing either "01/02/2007" or "02/02/2007". After creating the subset, the RStudio environment said I ended up with zero observations, but the same variables. How can I get a subset of the data with only rows containing "01/02/2007" and "02/02/2007"? I saw a similar post, but still got an error on my dataset. See link: Select multiple rows conditioning

Error when calculating values greater than 95% quantile using plyr

两盒软妹~` 提交于 2019-12-20 06:39:16
问题 My data is structured as follows: Individ <- data.frame(Participant = c("Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Bill", "Harry", "Harry", "Harry", "Harry","Harry", "Harry", "Harry", "Harry", "Paul", "Paul", "Paul", "Paul"), Time = c(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), Condition = c("Placebo", "Placebo", "Placebo", "Placebo", "Expr", "Expr", "Expr", "Expr", "Expr", "Expr", "Expr", "Expr", "Placebo", "Placebo",