FAQ Database Discussion Community


How JOIN Seq with Array in Clojure?

arrays,mongodb,clojure,seq
I would try to perform a SQL JOIN like on results from MongoDB. I have data to show on grid: seqgroup: ({:_id #<ObjectId 54db3ba76a5b2d5de2e7e990>, :group_name gr1, :usersingroup_id [#<ObjectId 54d1e37a2039b30a00b342ca> #<ObjectId 54d8ab240e81f5d1cbf6f691>]} {:_id #<ObjectId 54db46ba6a5b2d5de2e7e992>, :group_name gr2, :usersingroup_id [#<ObjectId 54d8af860e81f5d1cbf71da3> #<ObjectId 54d8ab240e81f5d1cbf6f691>]}) Instead of ObjectId for :usersingroup_id I would like to...

how do you make a sequence using along.with for unique values in r

r,seq
Lets suppose I have a vector of numeric values [1] 2844 4936 4936 4972 5078 6684 6689 7264 7264 7880 8133 9018 9968 9968 10247 [16] 11267 11508 11541 11607 11717 12349 12349 12364 12651 13025 13086 13257 13427 13427 13442 [31] 13442 13442 13442 14142 14341 14429 14429 14429...

Avoid the 'seq' command in Bash?

bash,seq
I'm having a discussion about the use of seq for small loop in a Bash script (for example a loop with 10 iterations). I say, for example, is better do this for i in {1..10} do echo "Welcome $i times" done than use seq for i in $(seq 10) do...

Scala: map a Map to list of tuples

list,scala,dictionary,tuples,seq
I tried to use Map.map to convert a map into a List of Tuples. However this fails. I did the following experiments: val m = Map(("a" -> 1), ("b" -> 2)) //> m : scala.collection.immutable.Map[String,Int] = Map(a -> 1, b -> 2) val r1 = m.map{ case (k,v) => v}...

Seq.map and Seq.mapi optimize away side effects when anonymous function returns unit?

dictionary,f#,seq,side-effects
While debugging a memoization function I found myself trying to find out whether Seq.mapi was actually iterating over a sequence, so I replaced an anonymous function with a printfn call like so: let x = "test" |> Seq.map (fun c -> c |> printfn "%c") Quite to my surprise, the...

Assigning a value for each dataset and plot it with ggplot

r,ggplot2,lapply,assign,seq
It can be complicated problem but I will try to explain it as much as I could. I have a sequenced dataset containing number of observations which should be processed before plotting. I want do it with a function. because I have another datasets in the directory (around 20) #reproducible...

How to loop through a range of decimal numbers in bash?

linux,bash,for-loop,seq
I'd like to generate a sequence of equally spaced decimal numbers. For example, I want to echo all numbers between 3.0 and 4.5, with step 0.1. I tried $ for i {3.0..4.5..0.1}; do echo $i; done, but this gives an error. I also tried $ for i in $(seq 3.0...

Add an index (or counter) to a dataframe by group in R

r,indexing,counter,plyr,seq
I have a df like ProjectID Dist 1 x 1 y 2 z 2 x 2 h 3 k .... .... I want to add a third column such that we have an incrementing counter for each ProjectID: ProjectID Dist counter 1 x 1 1 y 2 2 z 1...

How to go about a d-smooth sequence algorithm

algorithm,sorting,sequence,seq
I'm really struggling to design an algorithm to find d, which is the lowest value that can be added or subtracted (at most) to make a given sequence strictly increasing. For example.. say seq[] = [2,4,8,3,1,12] given that sequence, the algorithm should return "5" as d because you can add...

Scala: remove first column (first element in each row)

arrays,scala,seq
Given an var x: Array[Seq[Any]], what would be the most efficient (fast, in-place if possible?) way to remove the first element from each row? I've tried the following but it didn't work - probably because of immutability... for (row <- x.indices) x(row).drop(1) ...

Missing last sequence in seq() in R

r,seq
I have this example data by<-200 to<-seq(from=by,to=35280,by=by) Problem is that to ends at 35200 and ignore the last 80 which I need to involve in as last value. Is there any straigthforward way how to achieve it? I have tried along.with and length.out parameters but I cannot go trough....

add numbers to beginning of each line increasing by 1 every nth line

awk,sed,seq
Starting with number 1, how to add this number in front of the direct following next x lines, followed by number 2 also for the following next x lines, and so on, end must be by y lines, how to do that? 1 jeriro ieieie ieiue 1 ieirirp wzwezeg 1...

R creating a sequence table from two columns

r,data.frame,seq
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...

Reshape start-end time intervals to smaller intervals in R

r,apply,reshape,seq
Here is duration data by time intervals. id <- c("A", "B", "B", "B", "C", "C", "D", "E", "F", "F", "F", "F") start <- c(368, 200, 230, 788, 230, 521, 272, 306, 0, 162, 337, 479) end <- c(373.98, 229.98, 233.98, 842.98, 239.98, 639.98, 285.98, 306.98, 95.98, 162.98, 339.98, 539.98) value...

In R, why doesn't -1 + 1 = 0 [duplicate]

r,seq,cumsum
This question already has an answer here: Why are these numbers not equal? 3 answers Can someone please help me understand why -1 + 1 <> 0 ? Can someone please help me understand why I get three different values between the built-in function consum(), my function ct(), and...

How to generate random numbers in a data.frame with range

r,random,data.frame,seq
I have a data.frame which I want to generate random numbers each list by a sequence. I used sample function to create random numbers but even I created random numbers for list [[1]], for set [[2]] same numbers produced again. So, here how can I create different random numbers for...

Scala - finding first position in which two Seq differ

scala,diff,sequence,seq
Scala comes with the nice corresponds method: val a = scala.io.Source.fromFile("fileA").getLines().toSeq() val b = scala.io.Source.fromFile("fileB").getLines().toSeq() val areEqual = a.corresponds(b){_.equals(_)} if(areEqual) ... And I quite like the brevity of that. Is there a similar method already defined that will also report to me the first position in which the two sequences...

Subset sequence data in fasta file based on IDs stored in listed data frames

r,subsetting,fasta,seq
I am trying to subset one FASTA file (containing multiple sequences) into several smaller ones based on IDs I stored in a list of data frames (and I have a FASTA called fastafile like this: fastafile <- dput(fastafile) structure(list(r1 = "acatattggaggccgaaacaatgaggcgtgatcaactcagtatatcac", r2 = "ctaacctctcccagtgtggaacctctatctcatgagaaagctgggatgag", r3 = "atttcctcctgctgcccgggaggtaacaccctggacccctggagtctgca", r4 = "acatattggaggccgaaacaatgaggcgtgatcaactcagtatatcgg",...