seq is short for sequence. A sequence is an ordered list of objects (or events). Like a set, it contains members (also called elements or terms), and the number of terms (possibly infinite) is called the length of the sequence. Unlike a set, order matters, and exactly the same elements can appear multiple times at different positions in the sequence. Sometimes, sequence is used as a generic name for both list, array and set for convenience.
Questions tagged [seq]
730 questions
378
votes
5 answers
Difference between a Seq and a List in Scala
I've seen in many examples that sometimes a Seq is being used, while other times is the List...
Is there any difference, other than the former one being a Scala type and the List coming from Java?

opensas
- 60,462
- 79
- 252
- 386
102
votes
3 answers
Create sequence of repeated values, in sequence?
I need a sequence of repeated numbers, i.e. 1 1 ... 1 2 2 ... 2 3 3 ... 3 etc. The way I implemented this was:
nyear <- 20
names <- c(rep(1,nyear),rep(2,nyear),rep(3,nyear),rep(4,nyear),
…

Wesley Burr
- 1,224
- 3
- 9
- 9
86
votes
2 answers
What are examples of when seq_along works, but seq produces unintended results?
What are good examples of when seq_along will work, but seq will produce unintended results?
From the documentation of ?seq we have:
Note that it dispatches on the class of the first argument
irrespective of argument names. This can have…

Ricardo Saporta
- 54,400
- 17
- 144
- 178
80
votes
5 answers
Scala - What is the difference between size and length of a Seq?
What is the difference between size and length of a Seq? When to use one and when the other?
scala> var a :Seq[String] = Seq("one", "two")
a: Seq[String] = List(one, two)
scala> a.size
res6: Int = 2
scala> a.length
res7: Int = 2
It's the…

YoBre
- 2,520
- 5
- 27
- 37
72
votes
7 answers
Variables in bash seq replacement ({1..10})
Is it possible to do something like this:
start=1
end=10
echo {$start..$end}
# Ouput: {1..10}
# Expected: 1 2 3 ... 10 (echo {1..10})

Tyilo
- 28,998
- 40
- 113
- 198
71
votes
3 answers
How do I generate a list with a specified increment step?
How do I generate a vector with a specified increment step (e.g. 2)? For example, how do I produce the following
0 2 4 6 8 10

LostLin
- 7,762
- 12
- 51
- 73
67
votes
3 answers
Select every other element from a vector
Let's say I had a vector:
remove <- c(17, 18, 19, 20, 24, 25, 30, 31, 44, 45).
How do I select / extract every second value in the vector? Like so: 17, 19, 24, 30, 44
I'm trying to use the seq function: seq(remove, 2) but it doesn't quite work.
Any…

user1313954
- 901
- 2
- 11
- 14
58
votes
1 answer
Adding an item to an immutable Seq
Say, I have a sequence of strings as an input and I want to get a new immutable Seq which consists of elements of the input and an item "c". Here are two methods that I've discovered to be working:
assert(Seq("a", "b", "c") == Seq("a", "b") ++…

Nikita Volkov
- 42,792
- 11
- 94
- 169
45
votes
7 answers
Convert Java List to Scala Seq
I need to implement a method that returns a Scala Seq, in Java.
But I encounter this error:
java.util.ArrayList cannot be cast to scala.collection.Seq
Here is my code so far:
@Override
public Seq columnNames() {
List a = new…

Fundhor
- 3,369
- 1
- 25
- 47
42
votes
5 answers
Generate a sequence of characters from 'A'-'Z'
I can make a sequence of numbers like this:
s = seq(from=1, to=10, by=1)
How do I make a sequence of characters from A-Z? This doesn't work:
seq(from=1, to=10)

James Thompson
- 46,512
- 18
- 65
- 82
33
votes
6 answers
How to zero-pad numeric variables in zsh (and maybe also bash?)
In zsh, when I have to create a bunch of files with zsh, I usually do something like:
for x in $(seq 1 1000); do .....; done
This works fine, it gives me files with names foo-1.txt .. foo-1000.txt.
However, these files do not sort nicely, so I…

ervingsb
- 653
- 8
- 9
29
votes
4 answers
F#, char seq -> strings
A quick question that may be more of a rant (but I hope to be enlightened instead).
In F# a string is compatible with Seq such that "abcd" |> Seq.map f will work on a string.
This is a brilliant facility for working with strings, for example to take…
user1158550
26
votes
5 answers
Create a log sequence across multiple orders of magnitude
In order to set the custom break intervals for a log scale in a ggplot2 chart, I created the following vector from multiple sequences.
breaks <- c(seq(2000, 10000, by = 1000),
seq(20000, 100000, by = 10000),
seq (200000, 1000000, by…

Look Left
- 1,305
- 3
- 15
- 20
23
votes
4 answers
Generate series 1, 2,1, 3,2,1, 4,3,2,1, 5,4,3,2,1
I am trying to generate a vector containing decreasing sequences of increasing length, such as 1, 2,1, 3,2,1, 4,3,2,1, 5,4,3,2,1, i.e.
c(1, 2:1, 3:1, 4:1, 5:1)
I tried to use a loop for this, but I don't know how to stack or concatenate the…

FFB
- 255
- 2
- 7
21
votes
3 answers
piping seq to printf for number formatting
I'm trying to print the following pattern using printf and seq:
0000
0001
0002
0003
My problem is once I use:
seq 0 10 | xargs printf %04d
all my output is formatted into the same line likeso:
0000000100020003
I still can't get the hang of using…

Paolo
- 1,557
- 3
- 18
- 28