subset

Subset (list of lists) nested Lists

不问归期 提交于 2020-08-06 05:10:03
问题 I am trying to subset thead/tbody without directly calling rowlist$td$list$item$table$thead or rowlist[[td]][[list]][[item]][[table]][[thead]]. This unlist(rowlist, use.names=FALSE )[ grepl( "tbody", names(unlist(rowlist)))] serves my purpose except I need it as multiple rows (e.g. two tr's in tbody)(i can split it but seems counter intuitive . I know there should be a better way to work with HTML/XML but this is got I got for now. str(rowlist) List of 1 $ td:List of 1 ..$ list:List of 1 .. .

How to get all possible subsets of a character vector in R?

放肆的年华 提交于 2020-08-05 07:16:29
问题 Having the following vector: c("test1","test2","test3") I am trying to get a list or data frame containing the following entries: "test1" "test2" "test3" "test1" "test2" NA "test1" NA "test3" "test1" NA NA NA "test2" "test3" NA "test2" NA NA NA "test3" The goal would be to get all possible subsets while the order doesn't matter, that is "text1" "text2" NA is equivalent to "text2" "text1" NA. I very much appreciate any help! 回答1: You can use combn : res <- unlist(lapply(1:3, combn, x = c(

postgresql——SQL update fields of one table from fields of another one(列的批量更新)

安稳与你 提交于 2020-07-27 13:00:54
https://stackoverflow.com/questions/18797608/update-multiple-rows-in-same-query-using-postgresql 问题描述: SQL update fields of one table from fields of another one I have two tables: A [ID, column1, column2, column3] B [ID, column1, column2, column3, column4] A will always be subset of B (meaning all columns of A are also in B ). I want to update a record with a specific ID in B with their data from A for all columns of A . This ID exists both in A and B . Is there an UPDATE syntax or any other way to do that without specifying the column names , just saying "set all columns of A" ? I'm using

如何按给定索引处的元素对列表/元组进行排序(列表/元组)?

て烟熏妆下的殇ゞ 提交于 2020-07-27 06:04:41
问题: I have some data either in a list of lists or a list of tuples, like this: 我在列表列表或元组列表中都有一些数据,如下所示: data = [[1,2,3], [4,5,6], [7,8,9]] data = [(1,2,3), (4,5,6), (7,8,9)] And I want to sort by the 2nd element in the subset. 我想按子集中的第二个元素排序。 Meaning, sorting by 2,5,8 where 2 is from (1,2,3) , 5 is from (4,5,6) . 意思是,按2,5,8排序,其中 2 来自 (1,2,3) , 5 来自 (4,5,6) 。 What is the common way to do this? 常见的做法是什么? Should I store tuples or lists in my list? 我应该在列表中存储元组或列表吗? 解决方案: 参考一: https://stackoom.com/question/D6AV/如何按给定索引处的元素对列表-元组进行排序-列表-元组 参考二: https://oldbug.net/q/D6AV/How-to-sort-list-tuple-of

Delete runs of certain value before and after specific value

北城余情 提交于 2020-07-09 08:32:18
问题 I have a data frame with several columns. Based on the column 'activity', I want to remove entire contiguous runs of a specific value, 'pt', but only when they occur immediately before or after a run of 'outside'. In the simplified data below, there is one run where 'activity' is 'outside', and which have chunks of 'pt' before and after. These two 'pt' chunks should be removed. activity dist 1 home 1 2 pt 2 # <- run of 'pt' before run of 'outside': remove 3 pt 3 # <- 4 pt 4 # <- 5 outside 5 6

How to concisely deal with subsets when their lengths become zero?

被刻印的时光 ゝ 提交于 2020-06-27 16:53:13
问题 To exclude elements from a vector x , x <- c(1, 4, 3, 2) we can subtract a vector of positions: excl <- c(2, 3) x[-excl] # [1] 1 2 This also works dynamically, (excl <- which(x[-which.max(x)] > quantile(x, .25))) # [1] 2 3 x[-excl] # [1] 1 2 until excl is of length zero: excl.nolength <- which(x[-which.max(x)] > quantile(x, .95)) length(excl.nolength) # [1] 0 x[-excl.nolength] # integer(0) I could kind of reformulate that, but I have many objects to which excl is applied, say: letters[1:4][

For loop in R that calculates for the group and then the components

笑着哭i 提交于 2020-06-18 05:31:27
问题 I have a set of data and a loop containing numerous calculations for the data set, where the individual components of the set are split into a subset and cycled through one by one. However I need to be able to execute the same calculations across the original data set as a whole first. For a fictional data set called masterdata with 3 components (column D1) and numerous variables (X2-X10) as such: # masterdata # D1 X2 X3 X4 X5 X6 X7 X8 X9 X10 # A NA NA NA NA NA NA NA NA NA # B NA NA NA NA NA

Returning subset of properties from an array of objects

巧了我就是萌 提交于 2020-06-17 04:23:09
问题 I have an array of objects like var array = [{date:'01/01/2017',value1:200,value2:300,value3:400}] I am trying to get a subset of the object properties like var var newArray = [['01/01/2017',200],['01/01/2017',200],['01/01/2017',200]......] I do not want an array like this [[date:'',value2:],[date:'',value2:],[date:'',value13:]] But just directly a 2 D array from array of objects. Currently I am doing a for each on my array of objects and pushing the required properties in to an array an

Subset dataframe in R based on a list specified in a vector (using a 'starts with' expression or equivalent)

随声附和 提交于 2020-06-17 03:44:22
问题 I am trying to identify any participant taking statins in a dataset of over 1 million rows and subset based on this. I have a vector that includes all the codes for these medications (I've just made a few up for demonstration purposes), and I would next like to create a function that searches through the dataframe and identifies any case that has a medication code that "starts with" any of the characters listed in the df. The df looks like this: ID readcode_1 readcode_2 generic_name 1 1001

Subset dataframe in R based on a list specified in a vector (using a 'starts with' expression or equivalent)

怎甘沉沦 提交于 2020-06-17 03:43:08
问题 I am trying to identify any participant taking statins in a dataset of over 1 million rows and subset based on this. I have a vector that includes all the codes for these medications (I've just made a few up for demonstration purposes), and I would next like to create a function that searches through the dataframe and identifies any case that has a medication code that "starts with" any of the characters listed in the df. The df looks like this: ID readcode_1 readcode_2 generic_name 1 1001