rbind dataframes in a list of lists

I have a list of lists that looks like this: x[[state]][[year]]. Each element of this is a data frame, and accessing them individually is not a problem. However, I'd like to rbind data frames across multiple lists. More specifically, I'd like to have as output as many dataframes as I have years, that is rbind all the state data frames within each year. In other words, I'd like to combine all my state data, year by year, into separate data frames. I know that I can combine a single list into a

finding unique values from a list

Suppose you have a list of values x <- list(a=c(1,2,3), b = c(2,3,4), c=c(4,5,6)) I would like to find unique values from all list elements combined. So far, the following code did the trick unique(unlist(x)) Does anyone know a more efficient way? I have a hefty list with a lot of values and would appreciate any speed-up.

Ocaml - parameter type when checking for duplicates in a list

I've got a basic function which checks a list for duplicates and returns true if they are found, false otherwise. # let rec check_dup l = match l with [] -> false | (h::t) -> let x = (List.filter h t) in if (x == []) then check_dup t else true ;; Yet when I try to use this code I get the error Characters 92-93: let x = (List.filter h t) in ^ Error: This expression has

Replace individual list elements in Haskell?

I have a list of elements and I wish to update them: from this: ["Off","Off","Off","Off"] to this: ["Off","Off","On","Off"] As I am somewhat new to Haskell, I have been using (x:xs)!!y to extract and update individual components using the function: replace y z [] = [] replace y z (x:xs) | x==y = z:replace y z xs | otherwise = x:replace y z xs and then entering the following in ghci: (replace "Off" "On" ["Off",'Off","Off","Off"]) !! 2 I get the following: "On" I seem t

Subtracting mean from calculation puts answer in list?

I have a function that cycles through two sperate lists and combines them into one as follows: spread = Table[{gld[[i, 1]], (gld[[i, 2]] - gdx[[i, 2]]) }, {i, 1, Length[gld], 1}] This works fine, and generates answers in the form: {{2009, 6, 1}, 52.72} But when I add a subtraction, as follows: spread = Table[{gld[[i, 1]], (gld[[i, 2]] - gdx[[i, 2]]) - meanspread }, {i, 1, Length[gld], 1}] I get answers in the format: {{2009, 6, 1}, {-20.2896}} This cau

Column of lists inside a dataframe in R

Lets have the following dataframe inside R: df <- data.frame(sample=rnorm(1,0,1),params=I(list(list(mean=0,sd=1,dist="Normal")))) df <- rbind(df,data.frame(sample=rgamma(1,5,5),params=I(list(list(shape=5,rate=5,dist="Gamma"))))) df <- rbind(df,data.frame(sample=rbinom(1,7,0.7),params=I(list(list(size=7,prob=0.7,dist="Binomial"))))) df <- rbind(df,data.frame(sample=rnorm(1,2,3),params=I(list(list(mean=2,sd=3,dist="Normal"))))) df <- rbind(df,data.frame(sample=rt(1,3),params=I(list

List Partial sum in functional programming (recursion)

Possible Duplicate: Partial sum in Standard ML? Im new to functional programming and I have an assignment to compute partial sum of a list. E.g. - psum [1,1,1,1,1]; val it = [1,2,3,4,5] : int list Here is the my code so far. However my function just returns the list as it is. fun ppsum2([])=[] | ppsum2(x::L) = x::ppsum2(L); exception Empty_List; fun psum(L) : int list = if L=nil then raise Empty_List else psum2(L); psum([2,3,4]);

SML: Filtering list non-recursively

I'm trying to filter a list non-recursively but I'm not sure how to go about going it. For a simple example, say I have a list [1, 2, 3, 4, 5, 6, 7] and I want to filter it so it returns a list of numbers greater than 3, ie [4, 5, 6, 7]. I can do it recursively no problem but I'm stuck here. Unfortunately, I'm new to sml and the best I can think of is using map but I don't think map was made for this.

Count only numbers in list of numbers and letters

I'm new to Prolog and I can't seem to get the answer to this on my own. What I want is, that Prolog counts ever Number in a list, NOT every element. So for example: getnumbers([1, 2, c, h, 4], X). Should give me: X=3 getnumbers([], 0). getnumbers([_ | T], N) :- getnumbers(T, N1), N is N1+1. Is what I've got, but it obviously gives me every element in a list. I don't know how and where to put a "only count numbers".

Select RDF collection/list and iterate result with Jena

For some RDF like this: <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:blah="http://www.something.org/stuff#"> <rdf:Description rdf:about="http://www.something.org/stuff/some_entity1"> <blah:stringid>string1</blah:stringid> <blah:uid>1</blah:uid> <blah:myitems rdf:parseType="Collection"> <blah:myitem> <blah:myitemvalue1>7</blah:myitemvalue1> <blah:myitemvalue2&g

How to distinguish list's itemtap from itemtaphold event in Sencha Touch 2

I'm new to Sencha Touch 2.Today I encountered a problem,I want to add itemtap and itemtaphold events in a list's listeners,but I can't disable itemtap when itemtaphold fired.Usually,I would use a variable like dataView.config.istplhold to make this distinction in controller,but it doesn't work in listeners.Here is my code: itemTpl: ['<table><tr>'+ //'<td>{attachmentName}</td>'+ '<td width="40px;">{i}</td>'+ // '<td ><a

List remove first occurrence of an element in Prolog

I'm trying to remove the first occurrence of an element from a list in Prolog. My code: remove_first_X(X,[X|Xs],Xs). %remove X remove_first_X(X,[Y|Xs],[Y|Xs]) :- remove_first_X(X,Xs,Xs). Doesn't work: ?- remove_first_X(1,[1,2,3],[2,3]). true. ?- remove_first_X(1,[2,1,3],[2,3]). false. Please help! :-) Another attempt is closer: remove_first_X(X,[X|Xs],Xs). remove_first_X(X,[Y|Xs],[Y|Ys]) :- remove_first_X(X,Xs,Ys). But removes X after its first occurrence: ?- remove_first_X(1,

Prolog: between/3 with a list at the end

my question comes up because of this question Can you write between/3 in pure prolog? would it be possible to make between/3 and the third argument is a list so if you ask between(2,6,X). it comes X=[2,3,4,5,6] and not like X=2 X=3 X=4 .... I can’t figure out how this must work (all my solutions don’t work..) I’m a Prolog beginner so I have no idea.. sorry for the bad English.. Thanks for your help :)

In OCaml, why is there an auxiliary function in Core's List.find?

In Core, List.find is defined using an auxiliary function, as follows: let find l ~f = let rec find_aux = function | [] -> None | hd :: tl -> if f hd then Some hd else find_aux tl in find_aux l But it can be defined directly. For instance: let rec find l ~f = match l with | [] -> None | hd :: tl -> if f hd then Some hd else find tl f Is there any advantage in using an auxiliary function for defining a function such as List.find?

swi-prolog: how to sort list of lists by NTH element of sublist, ALLOWING DUPLICATES

(I have used 'asserta' to put a large csv file with several columns into the database.) Is there a way to sort numerically by column without removing duplicates? As you can see from my simple example (which sorts by the second column / element), the predsort method removes duplicates. I could work around this by switching and removing some columns and using msort, but am asking you specifically here for an alternative. Any advice would be v much appreciated ! mycompare(X,E1,E2):- E1=[_,A1]

Creating a list of lists passed as arguments to the function in LISP

I'm writing a code in LISP where I am taking 3 different lists from user as arguments to my function and then I want to create a new list of these lists.. I tried simple coding but it's not giving me desired output. Here's the code I wrote: (defun demo(n1 n2 n3) (setq list1 '(n1 n2 n3)) (print list1)) CL-USER 12 : 5 > (demo '(1 2 3) '(4 5 6) '(7 8 9)) (N1 N2 N3) (N1 N2 N3) When I run this code, instead of giving list of lists it's giving me the output: (n1 n2 n3) desired output i

Prolog: Graph representation of list and difference list

I've been trying to understand how a list and a difference list would look like in a graph structure. I understand the basic structure of a list like [a1,a2,a3,..an|[]]. But I can't grasp how a difference list would look like? like for example [1,2,3,4]-[3,4]

filter a List according to multiple contains

I want to filter a List, and I only want to keep a string if the string contains .jpg,.jpeg or .png: scala> var list = List[String]("a1.png","a2.amr","a3.png","a4.jpg","a5.jpeg","a6.mp4","a7.amr","a9.mov","a10.wmv") list: List[String] = List(a1.png, a2.amr, a3.png, a4.jpg, a5.jpeg, a6.mp4, a7.amr, a9.mov, a10.wmv) I am not finding that .contains will help me! Required output: List("a1.png","a3.png","a4.jpg","a5.jpeg")

How to read each element within a tuple from a list

I want to write a program which will read in a list of tuples, and in the tuple it will contain two elements. The first element can be an Object, and the second element will be the quantity of that Object. Just like: Mylist([{Object1,Numbers},{Object2, Numbers}]). Then I want to read in the Numbers and print the related Object Numbers times and then store them in a list. So if Mylist([{lol, 3},{lmao, 2}]), then I should get [lol, lol, lol, lmao, lmao] as the final result. My thought is to fi

How to use the module List in Oz

I found info about a module in Oz that contains procedures operating on lists here: https://mozart.github.io/mozart-v1/doc-1.4.0/base/list.html But I have been trying different procedures in different ways, for example: declare proc {Length L} I in {List.length +L ?I} {Browse I} end declare L=[1 2 3 4] in {Length L} And what I get is a type error, I hope you can help me to know why, I'm very new using OZ

Erlang: Remove single element from proplist

I'm trying to remove a single top element from a proplist. How would I go about doing this. I have a proplist like so: [{listA,[a,b,c]},{listB,[d,e]}] So how would I remove the top element from listA?

Prolog, skip adding elements to a list based on rules

I have some Prolog code, and would like to be able to skip adding an element to the Results list if the product of X and Y is greater than a certain value. Any idea how I would go about doing this? e.g. if Product > 10 The code I have so far make_quads(_,[],[]). make_quads(X,[Y|TAIL],[[X,Y,Sum,Product]|Result]):- make_quads(X,TAIL,Result), Product is X * Y, Product > 2, Sum is X + Y. The function is called as follows: ?- make_quads(5, [1,2,3,4,5,6], X). Which wo

Haskell: recursively process lists nested arbitrarily deep

I'm learning Haskell and would like to write functions to recursively process lists nested arbitrarily deep. For example I'd like to write recurReverse, which in the basis case, acts just like the built in reverse, but when passed a nested list, would reverse all the elements of the sublists recursively as well: recurReverse [1,2] >> [2,1] recurReverse [[1],[2],[3,4]] >> [[4,3],[2],[1]] recurReverse [[[1,2]]] >> [[[2,1]]] Currently I have the basic reverse down: rev [] = [

List Why can't coq infer the that 0+n=n in this dependently typed program?

I'm starting to use Coq and I'd like to define some dependently typed programs. Consider the following: Inductive natlist : nat -> Type := | natnil : natlist 0 | natcons : forall k, nat -> natlist k -> natlist (S k). Fixpoint natappend (n:nat) (l1: natlist n) (m:nat) (l2: natlist m) : natlist (n+m) := match l1 with | natnil => l2 | natcons _ x rest => natcons (n+m) x (natappend rest l2) end. So natlist k would be a list of nats of length k. The problem with the

material-ui dynamic nestedItems in List from JSON data

I'm building a node tree in React.js using { List, ListItem, MakeSelectable} from 'material-ui/List'. I will eventually wire up JSON data coming from an internal web service call. I have no problem declaratively creating a nested list: <List> ... <ListItem ... nestedItems={[ <ListItem ... What I want to do is programmatically create this nested structure from the JSON data. It's easy enough to instantiate individual <ListItem> components and .push them

List Iterating forward and backward

We have a double ended list of structs, e.g. LinkedList. I need to iterate forward and backward through the elements (like, 4 times forward then 2 times backward then 5 times forward). In C++ it would be: iter++; iter++; ... iter--; ... In Rust, I only see .next() and .rev() which is inconvenient (since after a few iterations I already do not know in which direction I've reversed iteration).

Unpack a list in Python

Say I have a MySQL table I access through MySQLDB. I have a standard SELECT statement: sql = "SELECT * FROM EMPLOYEE \ WHERE INCOME > '%d'" % (1000) I then execute it with the cursor and pluck out the columns as below. cursor.execute(sql) results = cursor.fetchall() for row in results: fname = row[0] lname = row[1] age = row[2] sex = row[3] income = row[4] Is it possible to assign all the column names in a single statement? Something like:

Haskell - Tuples and Lists as built-in types: how are they actually declared?

In chapter 2 of "A gentle introduction to Haskell", user-defined types are explained and then the notion that built-in types are, apart from a special syntax, no more different than user-defined ones: Earlier we introduced several "built-in" types such as lists, tuples, integers, and characters. We have also shown how new user-defined types can be defined. Aside from special syntax, are the built-in types in any way more special than the user-defined ones? The answer is no. (The special synt

How do i remove all the letters in a list if it repeats n number of times. where n is a number between 1-10

This is the list. list1 =['F', 'L', 'Y', 'W', 'B', 'E', 'G', 'A', 'L', 'K', 'R', 'U', 'B', 'E', 'T', 'L', 'H', 'G', 'E', 'C', 'K', 'Y', 'U', 'B', 'H', 'L', 'U', 'G', 'A', 'F', 'K', 'Y', 'F', 'M', 'P', 'U', 'B', 'K', 'F', 'G', 'I', 'O', 'N', 'S', 'Y'] I want to delete the letters that repeat n numbers of time. In the context of this problem n is 4. This is what i have tried so far. n = 4 alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","

How to remove from list if only given partial match

I have a situation where I want to remove items from a list. I only have part of the list item, so the typical remove from list isn't working for me since it's not a complete match. I want to delete all instances of the match, and not just the first match. I know exactly how many indexes are in the list item; however my search will only contain 3 of the 6 index items. I'm using Python 3.6 Name of list is DV This is what I'm trying so far: c = Brian,Eats,Dinner if c in DV: DV.remove(s

extracting numbers in list to dict of lists

I have a dict of lists that looks similarly to this: 'H82746': ['Hsa.1070', 'H82746', 'U1', 'SMALL', 'NUCLEAR', 'RIBONUCLEOPROTEIN', 'C', ';.', '1.75', '1.46', '1.75', '1.69', '1.30', '1.11', '1.42', '1.11', '1.92', '0.99', '0.65', '1.69', '1.39', '1.29', '1.55', '2.00', '1.16', '0.70', '1.48', '0.78', '1.52', '1.28', '1.50', '0.79', '1.31', '1.56', '1.33', '1.66', '1.67', '1.34', '1.48', '0.38', '0.76', '1.27', '1.66', '1.12', '1.40', '1.23', '1.66', '1.58', '2.33', '1.25', '0.90', '0.63', '0.

Skipping list of lists elements

I have this nested list: list = [[1, 2, 3, 4], [2, 7, 2, 1], [3, 3, 7, 5], [4, 4, 1, 7]] And I'm trying to skip the first list of this nested list, and the first element of each list. I want it to become like this: list = [[7, 2, 1], [3, 7, 5], [4, 1, 7]] So far I have this: % skip first list in list of lists skip_first_list([_|Tail], Tail). % attemping to skip first element in each of the lists skip_first_list([[_ | HeadTail] | Tail], X) :-

Changing the Value of a label from a list.

I am trying to make a guessing game where the program will display a sequence of a number one at a time. I have the sequence randomly generated from a list but I have not been able to display the values in the list one at a time. I want to change the label using bind but I can't seem to make it work. public class Tutorial extends Application { Stage window; Scene scene1, scene2; Label label; public static void main(String[] args) { launch(args); } public v

Prolog - creating a new list of the elements from an original list after doubling each value?

Example of trace produced. I'm trying to write a predicate, listDouble(L1, L2), where every element in L2 is the double of its corresponding element in L1 (i.e. if L1 = [1, 2, 3] then L2 = [2, 4, 6]), and this is my code so far: listDouble([], [L2]). listDouble([H|T], [L2|_]):- L is H * 2, listDouble(T, [L]). However, it's not working and I think I'm struggling to understand how to add the double of each element to L2?

Haskell make a list of the variables of a list

Suppose I have the data data Expense = MkExpense Double String deriving (Eq,Ord) and a function balanced :: [Expense] -> Double -> Bool balanced expenses epsilon = let amounts = ... in maximum amounts - minimum amounts < epsilon; which computes wether the list of expenses is balances (i.e. everyone paid the same with a maximum difference of epsilon due to floating point errors), the epsilon has a value of 0.01. The alogrithm is correct, but where the three dots are, I want t

Haskell filtering a nested list with specific data constructors

Suppose I have the data type data Joke = Funny String | Lame String and say I have the following nested list [[Funny "Haha", Lame "boo"], [Funny "Haha"], [Lame "BOO"]] How would I go about filtering such a nested list so that any list within the nested list that contains Funny "Haha" is removed? In other words, I'm trying to filter the list so that I receive the following result: [[Lame "BOO"]] Any list that contains Funny "Haha" is removed. Would appreciate any help, I'm having a te

Cycling through a list until I find the correct sequence?

I need to cycle through a list in Prolog until a valid sequence appears. In this case the sequence goes "u" "r" "d" "l". The lists will only be made up of those characters. I already have a method that returns a list of all possible cycles, such as this: ?- all_cases(["l", "u", "r", "d"], S). S = [["l", "u", "r", "d"], ["u", "r", "d", "l"], ["r", "d", "l", "u"], ["d", "l", "u", "r"]]. As you can see, the second list is in the order I need. Now the problem is, I need to traverse that list (S)

Can one apply a macro to an argument list?

My goal is to be able to apply a macro to an argument list in the same way the apply primitive procedure applies a procedure to an argument list. The list will already be evaluated at the time of application of the macro, there is no way around that and that’s fine; I am wondering if there is any way to programmatically “splice” the list into the macro application (in the same sense as with unquote-splicing). The difficulty resides in that one cannot pass the macro identifier as an argument.

kotlin: extracting from list

I have a list of Int items say Now I want to call a function process(item1, item2, item3, item4) How can I do this in kotlin. I want to pass how much ever items are present in the list to the method. The method accepts variable number of arguments I want to call this method from firbase mlk library public FirebaseVisionBarcodeDetectorOptions.Builder setBarcodeFormats(@BarcodeFormat int var1, @BarcodeFormat int... var2) { } So I need to call setBarcodeFormats(is there a way in kot

Dart compare unordered Lists with Objects

I have following problem. There are two Lists with Articles in it. In the following example the result prints me false. But the Articles are the same. I think thats, because these are different objects, if I add in both lists article1, it will be true. I also tried DeepCollectionEquality.unordered().equals from this issue: How can I compare Lists for equality in Dart? But it is also giving me FALSE back. In my real project, I have two Lists with Articles in it. These lists are not sorted, s

save a certain random number of turtles in a list

I have 10 turtles and I want to work on 3 of them chosen randomly. How do I select 3 turtles randomly and save those exact turtles to use them later? I figured how to print the list I want to save ask n-of 3 turtles [print int (who )] but I do not know how to save these turtles in a list.

Ansible - getting an item from one list based on a value from another

I have a list of site information like this: sites: - {host: host1, path: path1, db: db1 } - {host: host2, path: path2, db: db2 } - {host: host3, path: path3, db: db3 } And database info in lists like this: mysql_databases: - { name: db1, encoding: utf8mb4, collation: utf8mb4_unicode_ci } - { name: db2, encoding: utf8mb4, collation: utf8mb4_unicode_ci } - { name: db3, encoding: utf8mb4, collation: utf8mb4_unicode_ci } mysql_users: - { name: db1, host: "%", password: pass1, priv:

Robotframework: How to use a value form one list as a part of the name of another list

I am trying to create a list whose name should include one of the values from another list. To simplify, I have created a following simple example. Create first list @{list.1} create list 1 2 3 log ${list.1}[1] Get the second value from the list ${list1_2ndValue} = get from list ${list.1} 1 log ${list1_2ndvalue} Use this value in a new list as part of its name. New list name should be @{list.2} @{list.${list1_2ndValue}} create list a b c It fails with No keyword

How can I iterate over a Xamarin.Forms.Maps Map.Pins list while modifying the list?

I'm working on a Xamarin.Forms app the utilizes the Maps package. The Map object contains an IList Pins which stores the list of Pin objects that contain Label, Position and other properties. I am attempting to update this Pins list by comparing their Position to a Collection of custom objects that contain the same properties (ID, Position, etc) as well as whether or not they exist on this list anymore, and removing them accordingly. To elaborate, with every update, I want to iterate through th

Put some ListB into ListA as items, then clear ListB and ListA is gone too

I have 2 List as I code here. List<Detail> orderDetailList = List(); List<List> allOrders = List(); var result; String tmpCustomerName; My data came from my database as json, and here is some of my code. await Dio().get(myURL).then((value) async {result = json.decode(value.data)}); for (var item in result) { OrdersDetailModel ordersDetailModel = OrdersDetailModel.fromJson(item); setState(() { orders.add(ordersDetailModel); customerName = ordersDetailModel.customerName;

How to split a list which contains forwardslash in pyspark

Hi I have a list as below [(datetime.datetime(2020,8,20,19,40,27,tzinfo=tzlocal()), 'AAA/v1/b1/c1/text.txt'), (datetime.datetime(2020,8,20,14,48,28,tzinfo=tzlocal()), 'BBB/v2/b2/c2/text1.txt')] how do i split, so the output looks like below Timestamp V B C T 2020/8/20 19:40:27 v1 b1 c1 text.txt 2020/8/20 14:48:28 v2 b2 c2 text1.txt

List diverging implicit expansion for type scala.math.Ordering

I'm sorry for this question but I haven't been able to get an answer from the previous questions. I have a Scala class case class Problem ( ref: Ref, v1: Option[String], v2: Option[Int], v3: Option[Int] ) extends Ordered[Problem] { def v = ref.v def compare(other: Problem) = { import scalaz._ import Scalaz._ val v1Comp = ( v1 |@| other.v1 ) { case (r1, r2) => r1.compare(r2)} val v2Comp = ( v2 |@| other.2 ) { case (sr1, sr2) => sr1.compare(s

Removing values from lists using comparisons (Python3)

I'm using Python3. I have 2 lists for this example: G1 = [0, 5, 10, 18, 24, 31, 40] G2 = [0, 8, 15, 28, 37, 50, 61] Is it possible to get Python to take the last element in a list (in G1 this is 40), and then remove every element from G2 whose value is < 40? The end goal would be for G2 to read: [50, 61]

  1    2   3   4   5   6  ... 下一页 最后一页 共 55 页