seq

adding element to the end of sequence in C struct

送分小仙女□ 提交于 2020-01-05 07:41:30
问题 #include "seq.h" #include <stdio.h> #include <stdlib.h> typedef struct stack_node { ETYPE data; struct stack_node *prev, *next; }NODE; struct seq_struct { // "Container" struct NODE* top, *bottom; int size; }; /** * DESCRIPTION: adds a new element to the "back" of * the seq * * [2 4] * add_back 7 * [2 4 7] * * */ void seq_add_back(Seq seq, ETYPE val){ NODE* endq = malloc(sizeof(NODE)); endq->next =NULL; endq->prev = seq->bottom; endq->data = val; seq->bottom->next=endq; seq->bottom = endq;

How to extract data from iterating a sequence

前提是你 提交于 2020-01-05 06:15:24
问题 csvData1 contains the data in a .csv file. I've created a sequence out of just two of the columns in the spreadsheet ("GIC-ID", "COVERAGE DESCRIPTION") let mappedSeq1 = seq { for csvRow in csvData1 do yield (csvRow.[2], csvRow.[5]) } Looking in the Visual Studio debugger x winds up being a System.Tuple<string,string> . for x in mappedSeq1 do printfn "%A" x printfn "%A" x.ToString Here is the result of executing for x in mappedSeq1 ("GIC-ID", "COVERAGE DESCRIPTION") <fun:main@28> I am having

How to extract data from iterating a sequence

本小妞迷上赌 提交于 2020-01-05 06:15:13
问题 csvData1 contains the data in a .csv file. I've created a sequence out of just two of the columns in the spreadsheet ("GIC-ID", "COVERAGE DESCRIPTION") let mappedSeq1 = seq { for csvRow in csvData1 do yield (csvRow.[2], csvRow.[5]) } Looking in the Visual Studio debugger x winds up being a System.Tuple<string,string> . for x in mappedSeq1 do printfn "%A" x printfn "%A" x.ToString Here is the result of executing for x in mappedSeq1 ("GIC-ID", "COVERAGE DESCRIPTION") <fun:main@28> I am having

Print a multiplication table with minimal code

試著忘記壹切 提交于 2019-12-29 08:22:35
问题 In R, what is the fastest way(shortest code) to print multiplication table? The functions seq rep and the bind functions help, but I'm looking for the shortest line(s) of code to do this. rbind("1\'s"=1:12, "2\'s"=seq(2,24,2), "3\'s"=seq(3,36,3), "4\'s"=seq(4,48,4), "5\'s"=seq(5,60,5), "6\'s"=seq(6,72,6)) Prints the 1's through 6's going across (horizontally). Anyone know how to perform this in a more compact way? 回答1: tbl <- outer(1:6, 1:12, "*") rownames(tbl) <- paste(1:6, "'s", sep="") tbl

Print a multiplication table with minimal code

心已入冬 提交于 2019-12-29 08:22:09
问题 In R, what is the fastest way(shortest code) to print multiplication table? The functions seq rep and the bind functions help, but I'm looking for the shortest line(s) of code to do this. rbind("1\'s"=1:12, "2\'s"=seq(2,24,2), "3\'s"=seq(3,36,3), "4\'s"=seq(4,48,4), "5\'s"=seq(5,60,5), "6\'s"=seq(6,72,6)) Prints the 1's through 6's going across (horizontally). Anyone know how to perform this in a more compact way? 回答1: tbl <- outer(1:6, 1:12, "*") rownames(tbl) <- paste(1:6, "'s", sep="") tbl

Split seq in F#

守給你的承諾、 提交于 2019-12-29 07:37:06
问题 I should split seq<a> into seq<seq<a>> by an attribute of the elements. If this attribute equals by a given value it must be 'splitted' at that point. How can I do that in FSharp? It should be nice to pass a 'function' to it that returns a bool if must be splitted at that item or no. Sample: Input sequence: seq: {1,2,3,4,1,5,6,7,1,9} It should be splitted at every items when it equals 1, so the result should be: seq { seq{1,2,3,4} seq{1,5,6,7} seq{1,9} } 回答1: All you're really doing is

creating sequence of dates for each group in r

杀马特。学长 韩版系。学妹 提交于 2019-12-29 00:07:06
问题 I have a dataset that looks like this: ID created_at MUM-0001 2014-04-16 MUM-0002 2014-01-14 MUM-0003 2014-04-17 MUM-0004 2014-04-12 MUM-0005 2014-04-18 MUM-0006 2014-04-17 I am trying to introduce new column that would be all dates between start date and defined last day (say, 12th-july-2015). I used seq function in dplyr but getting an error. data1 <- data1 %>% arrange(ID) %>% group_by(ID) %>% mutate(date = seq(as.Date(created_at), as.Date('2015-07-12'), by= 1)) the error which I am getting

R creating a sequence table from two columns

若如初见. 提交于 2019-12-28 04:33:12
问题 I have a table as below product=c("a","b","c") min=c(1,5,3) max=c(1,7,7) dd=data.frame(product,min,max) > dd product min max 1 a 1 1 2 b 5 7 3 c 3 7 I want to create a table which will look like below. I want to create one row for each value between and including min and max for a product product mm a 1 b 5 b 6 b 7 c 3 c 4 c 5 c 6 c 7 How can i do it using R? is there any package which would give quick results? 回答1: With base R, you could do something like: data.frame(product=rep(dd$product,

F# Threading Changing State Through Unfold

风流意气都作罢 提交于 2019-12-25 16:27:37
问题 I'm trying to process a sequence of items whereby the process step relies on some additional cumulative state from the prior items (ordering isn't important). Essentially: I have a Seq<'A> I have a (Type * int) list referred to as the skip list I have a process step 'A -> (Type * int) list -> 'B option This takes the current skip list The method in question essentially: Seq<'A'> -> (Type * int) list -> (Type * int) list So we take a bunch of input items and an initial skip list and produce a

Column of sequence with repeated elements based on column with dates [duplicate]

偶尔善良 提交于 2019-12-25 12:48:12
问题 This question already has answers here : Increment by 1 for every change in column (4 answers) Closed 2 years ago . Consider a data frame ordered by a column with dates: df=data.frame(event=1:12, subject=rep("M325",12), date=c(rep("2017-11-01",4),rep("2017-11-14",8))) What I want is to create a fourth column with a sequence from 1 to the next unique date, with every element in the sequence repeated every i- th date. For example: event subject date num 1 1 M325 2017-11-01 1 2 2 M325 2017-11-01