nested

tidyverse - delete a column within a nested column/list

社会主义新天地 提交于 2021-01-28 05:24:50
问题 I have the following data: (Note: I'm using the current github version of dplyr within tidyverse which offerse some new experimental functions, like condense - which I'm using below, but I think that's not relevant for my problem/question). library(tidyverse) library(corrr) dat <- data.frame(grp = rep(1:4, each = 25), Q1 = sample(c(1:5, NA), 100, replace = TRUE), Q2 = sample(c(1:5, NA), 100, replace = TRUE), Q3 = sample(c(1:5, NA), 100, replace = TRUE), Q4 = sample(c(1:5, NA), 100, replace =

list comprehension creating nested lists

限于喜欢 提交于 2021-01-28 04:37:06
问题 I'd like to create nested lists of days per month list per year list: [[ 31, 29, 31, 30 ], [ 31, 28, 31, 30 ] ] with mm = [ 1, 2, 3, 4 ] yy = [ 2012, 2013 ] but my code: [ [ result.append( calendar.monthrange( y, m )[ 1 ] ) for m in mm] for y in yy ] produces: [31, 29, 31, 30, 31, 28, 31, 30 ] Can someone please tell me what I've done wrong? Thanks. BSL 回答1: So, I'm assuming the full code looks something like this: result = [] [ [ result.append( calendar.monthrange( y, m )[ 1 ] ) for m in mm]

Understanding variable scope in nested functions in Python

ε祈祈猫儿з 提交于 2021-01-28 03:14:59
问题 I have the following functions in Python3.7 def output_report(): sheet_dict = {1: 'All', 2: 'Wind', 3: 'Soalr'} sheet_name = sheet_dict[sheet_num] file_name = f'{file_name}_{sheet_name}_row_{row_num}.csv' if row_num else f'{file_name}_{sheet_name}.csv' return file_name def test_file(x): file_name = output_report(sheet_num) return f'{x}_{file_name}' def good_func(): sheet_num = 2 row_num = 2 a = test_file('new file') return a when I call: good_func() It raises an error that: NameError: name

Using a nested lookup table to find values above thresholds in second table and quantify them in R

僤鯓⒐⒋嵵緔 提交于 2021-01-28 02:42:17
问题 I’m analyzing river streamflow data with R language and I have two nested lists. First holds data (Flowtest) from different river reaches called numbers such as 910, 950, 1012 and 1087. I have hundreds of daily streamflow measurements (Flow), but as I’m preparing yearly statistics the exact day and month doesn’t matter. Each measurement (Flow) is referenced to a year (Year) in the Flowtest table. Flowtest <- list("910" = tibble(Year = c(2004, 2004, 2005, 2005, 2007, 2008, 2008), Flow=c(123,

Using a nested lookup table to find values above thresholds in second table and quantify them in R

前提是你 提交于 2021-01-27 23:09:54
问题 I’m analyzing river streamflow data with R language and I have two nested lists. First holds data (Flowtest) from different river reaches called numbers such as 910, 950, 1012 and 1087. I have hundreds of daily streamflow measurements (Flow), but as I’m preparing yearly statistics the exact day and month doesn’t matter. Each measurement (Flow) is referenced to a year (Year) in the Flowtest table. Flowtest <- list("910" = tibble(Year = c(2004, 2004, 2005, 2005, 2007, 2008, 2008), Flow=c(123,

How can I retrieve dynamically specified, arbitrary and deeply nested values from a Javascript object containing strings, objects, and arrays?

安稳与你 提交于 2021-01-27 13:15:50
问题 UPDATE: While there is good value to the code provided in the answers below, an improved version of this question, and its answer, can be found here. EDIT: Correcting the sample data object and simplifying (hopefully) the question GOAL: Given the below object, a function should parse the object through all its nestings and return the values that correspond to the keypath string argument, which might be a simple string, or include bracketed/dotted notation. The solution should work in Angular

Java 8 nested null check for a string in a map in a list

℡╲_俬逩灬. 提交于 2021-01-27 11:50:47
问题 I need to do a series of null checks ( nested null-checks ) to get an array of strings like below String[] test; if(CollectionUtils.isNotEmpty(checkList)){ if(MapUtils.isNotEmpty(checkList.get(0))){ if(StringUtils.isNotBlank(checkList.get(0).get("filename"))){ test = checkList.get(0).get("filename").split("_"); } } } Is there a better way, maybe using Java8 Optional, to perform these kind of nested checks? I unsuccessfully tried to use Optional with flatmap / map. 回答1: You could use a long

Java 8 nested null check for a string in a map in a list

谁说胖子不能爱 提交于 2021-01-27 11:46:27
问题 I need to do a series of null checks ( nested null-checks ) to get an array of strings like below String[] test; if(CollectionUtils.isNotEmpty(checkList)){ if(MapUtils.isNotEmpty(checkList.get(0))){ if(StringUtils.isNotBlank(checkList.get(0).get("filename"))){ test = checkList.get(0).get("filename").split("_"); } } } Is there a better way, maybe using Java8 Optional, to perform these kind of nested checks? I unsuccessfully tried to use Optional with flatmap / map. 回答1: You could use a long

How to create a nested array of objects from flat array of objects?

别等时光非礼了梦想. 提交于 2021-01-01 21:16:25
问题 I am still learning and need some guidance on how to form a complex nested array of objects from a JSON flat file. Here is the current input: [ {"id":"US-AL","state":"Alabama","industry":"All","category":"Cable Related Services","itemid":"12290","item":"Basic Cable Services","answer":"Exempt","explanation":"The sale of these services is not subject to sales tax.","citation":"Ala. Code sec. 40-23-1; Ala. Code sec. 40-23-2"}, {"id":"US-AL","state":"Alabama","industry":"All","category":"Cable

Nested list to dataframe [using purrr + map]

别来无恙 提交于 2021-01-01 09:11:40
问题 I've looked at a lot of posts so I'm sorry if this is redundant, but was hoping to get some help flattening a nested list: test <- list() test <- c( list("A" = c(list("1"), list("2"), list("3"))), list("B" = c(list("4"), list("5"), list("6"))) ) Desired Output name subcat 1 A 1 2 A 2 3 A 3 4 B 4 5 B 5 6 B 6 I'm struggling to write a nested for loop but I'd really like to use purrr or something more elegant to create a dataframe with two columns: the subcat column, and a repeated column for