subset

Getting 1D Subsets of Multi dimensional arrays in julia

∥☆過路亽.° 提交于 2019-12-06 07:24:43
I have a multi dimensional array in julia: julia> ac.value 3x100x3 Array{Float64,3}: [:, :, 1] = 0.29238 0.0751815 0.00843636 … -0.0143826 0.0403283 0.0225896 0.263146 0.080687 0.000462262 -0.00635778 0.0307563 0.0379104 0.992458 0.986423 0.980587 0.561173 0.55516 0.549105 [:, :, 2] = 0.362155 0.13406 0.0741124 … 0.0231614 0.0156455 0.0121797 0.325581 0.11181 0.0447847 0.0098042 0.0193873 0.0146943 0.914888 0.852297 0.796608 -0.0500265 -0.0551787 -0.0520171 [:, :, 3] = 0.269976 0.108082 0.0441809 … 0.0249861 0.0128778 0.0168318 0.218475 0.0997567 0.0532782 0.0243412 0.00742072 0.00978782 0

R xts object subseting xts object with multiple days of intraday data for certain hours

♀尐吖头ヾ 提交于 2019-12-06 06:59:45
问题 Is there a way in xts object to do the same as below but for xts object with multiple days of intraday data? The below works like a clock but for one day of data. If I pass xts from 22nd to 26th it does not. It seems like subseting intraday data in xts across multiple days is not possible to be done in one go but rather need to first split data per each day and then use this xts functionality. Is this correct? indexTZ(tdata) = "GMT" plotdata= tdata['20110822 10:00:00/20110822 12:00:00'] >

Generate all possible subgraphs of a directed graph keeping the number of vertices

我怕爱的太早我们不能终老 提交于 2019-12-06 05:07:29
I have two lists of vertices: V and S . I would like to generate all possible directed graphs from V and S so, that each vertex from V has only one out-edge and exactly one in-edge, and each vertex from S can have any number of in- and out- edges. Each graph in the result should contain exactly all vertices from V and from S . The result can contain both connected and disconnected graphs. First I thought it was a powerset-related problem, but powerset has many other sets that may contain just one element (and I do not need those). My current strategy is to: find all pairs between vertices from

Trying to use user-defined function to populate new column in dataframe. What is going wrong?

扶醉桌前 提交于 2019-12-06 03:47:16
Super short version: I'm trying to use a user-defined function to populate a new column in a dataframe with the command: TestDF$ELN<-EmployeeLocationNumber(TestDF$Location) However, when I run the command, it seems to just apply EmployeeLocationNumber to the first row's value of Location rather than using each row's value to determine the new column's value for that row individually. Please note: I'm trying to understand R, not just perform this particular task. I was actually able to get the output I was looking for using the Apply() function, but that's irrelevant. My understanding is that

Subset multiple columns in R - more elegant code?

半腔热情 提交于 2019-12-06 03:07:12
问题 I am subsetting a dataframe according to multiple criteria across several columns. I am choosing the rows in the dataframe that contain any one of several values defined in the vector "criteria" in any one of three different columns. I have some code that works, but wonder what other (more elegant?) ways there are to do this. Here is what I've done: criteria <-c(1:10) subset1 <-subset(data, data[, "Col1"] %in% criteria | data[, "Col2"] %in% criteria | data[, "Col3"] %in% criteria) Suggestions

Pandas best way to subset a dataframe inplace, using a mask

青春壹個敷衍的年華 提交于 2019-12-06 02:02:07
问题 I have a pandas dataset that I want to downsize (remove all values under x). The mask is df[my_column] > 50 I would typically just use df = df[mask] , but want to avoid making a copy every time, particularly because it gets error prone when used in functions (as it only gets altered in the function scope). What is the best way to subset a dataset inplace? I was thinking of something along the lines of df.drop(df.loc[mask].index, inplace = True) Is there a better way to do this, or any

Subset dataframe where date is within x days of a vector of dates in R

六月ゝ 毕业季﹏ 提交于 2019-12-06 01:51:13
问题 I have a vector of dates e.g. dates <- c('2013-01-01', '2013-04-02', '2013-06-10', '2013-09-30') And a dataframe which contains a date column e.g. df <- data.frame( 'date' = c('2013-01-04', '2013-01-22', '2013-10-01', '2013-10-10'), 'a' = c(1,2,3,4), 'b' = c('a', 'b', 'c', 'd') ) And I would would like to subset the dataframe so it only contains rows where the date is less than 5 days after any of the dates in the 'dates' vector. i.e. The initial dataframe looks like this date a b 2013-01-04

Row-wise cor() on subset of columns using dplyr::mutate()

孤人 提交于 2019-12-06 01:21:43
set.seed(8) df <- data.frame( A=sample(c(1:3), 10, replace=T), B=sample(c(1:3), 10, replace=T), C=sample(c(1:3), 10, replace=T), D=sample(c(1:3), 10, replace=T), E=sample(c(1:3), 10, replace=T), F=sample(c(1:3), 10, replace=T)) Would like to pass a subset of columns into a dplyr mutate() and make a row-wise calculation, for instance cor() to get correlation between column A-C and D-F, but cannot figure out how. Found SO inspiration here , here and here , but nevertheless failed to produce an acceptable code. For instance, I tried this: require(plyr) require(dplyr) df %>% rowwise() %>% mutate(c

regression on subsets for unique factor combinations using lm

我怕爱的太早我们不能终老 提交于 2019-12-06 00:33:46
I would like to automate a simple multiple regression for the subsets defined by the unique combinations of the grouping variables. I have a dataframe with several grouping variables df1[,1:6] and some independent variables df1[,8:10] and a response df1[,7]. This is an excerpt from the data. structure(list(Surface = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("NiAu", "Sn"), class = "factor"), Supplier = structure(c(1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), ParticleSize = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L),

Finding the product of each of the (n-1) subsets of a given array

末鹿安然 提交于 2019-12-05 22:28:26
问题 I'm sorry for deleting the original question, here it is: We have a bag or an array of n integers, we need to find the product of each of the (n-1) subsets. e.g: S = {1, 0, 3, 6} ps[1] = 0*3*6 = 0; ps[2] = 1*3*6 = 18; etc. After discussions, we need to take care of the three cases and they are illustrated in the following: 1. S is a set (contains one zero element) for i=1 to n if s[i]=0 sp[i] = s[1] * s[2] * ...* s[i-1] * s[i+1] *.....*s[n] else sp[i] = 0; 2. S is a bag (contains more than