seq

(zsh brace expansion | seq) for character lists - how?

拥有回忆 提交于 2019-11-27 10:58:30
问题 Bash allows me to write the statement, $ for i in {h..k} ; do echo $i ; done but zsh only allows number list expansion such as {8..13} . What's the best workaround? Something like seq for characters... 回答1: As this is still a top google result, an updated answer: The current release supports bash style {c1..c2} where c1 and c2 are characters: An expression of the form ‘ {c1..c2} ’, where c1 and c2 are single characters (which may be multibyte characters), is expanded to every character in the

How to produce cartesian product in bash?

半腔热情 提交于 2019-11-27 06:45:52
问题 I want to produce such file (cartesian product of [1-3]X[1-5] ): 1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 3 4 3 5 I can do this using nested loop like: for i in $(seq 3) do for j in $(seq 5) do echo $i $j done done is there any solution without loops? 回答1: Combine two brace expansions! $ printf "%s\n" {1..3}" "{1..5} 1 1 1 2 1 3 1 4 1 5 2 1 2 2 2 3 2 4 2 5 3 1 3 2 3 3 3 4 3 5 This works by using a single brace expansion: $ echo {1..5} 1 2 3 4 5 and then combining with another one:

Select every other element from a vector

房东的猫 提交于 2019-11-27 00:59:22
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 help is greatly appreciated. remove[c(TRUE, FALSE)] will do the trick. How it works? If logical vectors are used for indexing in R, their values are recycled if the index vector is shorter than the vector containing the values. Here, the vector remove contains ten values. If the index vector c(TRUE, FALSE) is used, the actual command is: remove[c

Difference between a Seq and a List in Scala

一曲冷凌霜 提交于 2019-11-26 12:34:01
问题 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? 回答1: In Java terms, Scala's Seq would be Java's List , and Scala's List would be Java's LinkedList . Note that Seq is a trait , which is equivalent to Java's interface , but with the equivalent of up-and-coming defender methods. Scala's List is an abstract class that is extended by Nil and :: ,

Select every other element from a vector

末鹿安然 提交于 2019-11-26 10:57:34
问题 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 help is greatly appreciated. 回答1: remove[c(TRUE, FALSE)] will do the trick. How it works? If logical vectors are used for indexing in R, their values are recycled if the index vector is shorter than the vector containing the values. Here, the

Generate an incrementally increasing sequence like 112123123412345

淺唱寂寞╮ 提交于 2019-11-26 08:37:25
问题 Basically I want to generate a sequence, say: n is 2, the sequence will be 112 n is 3, sequence is 112123 n is 5, sequence is 112123123412345 I did come up with a solution n=5 seq=1 for (i in 2:n){ seq=c(seq,rep(1:n,len=i)) } I am wondering if there is a way can do it without for loop? 回答1: Use sequence : > sequence(1:5) [1] 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 回答2: Here is one possibility: n<-5 unlist(lapply(1:n,function(x) 1:x)) ## [1] 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 回答3: It'd do something like: do

Sequence of Repeated Values in R

£可爱£侵袭症+ 提交于 2019-11-26 04:44:57
This is a very basic question, but it's annoying me, so I'm asking. 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), rep(5,nyear),rep(6,nyear),rep(7,nyear),rep(8,nyear)) which works, but is clumsy, and obviously doesn't scale well. How do I repeat the N integers M times each in sequence? I tried nesting seq() and rep() but that didn't quite do what I wanted. I can obviously write a for loop that will do it, but this also seems clumsy -- there should be an

Sequence of Repeated Values in R

让人想犯罪 __ 提交于 2019-11-26 01:53:58
问题 This is a very basic question, but it\'s annoying me, so I\'m asking. 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), rep(5,nyear),rep(6,nyear),rep(7,nyear),rep(8,nyear)) which works, but is clumsy, and obviously doesn\'t scale well. How do I repeat the N integers M times each in sequence? I tried nesting seq() and rep() but that didn\'t quite do what I wanted.

Variables in bash seq replacement ({1..10}) [duplicate]

你离开我真会死。 提交于 2019-11-26 00:55:53
问题 This question already has an answer here: How do I iterate over a range of numbers defined by variables in Bash? 20 answers 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}) 回答1: In bash, brace expansion happens before variable expansion, so this is not directly possible. Instead, use an arithmetic for loop: start=1 end=10 for ((i=start; i<=end; i++)) do echo "i: $i" done OUTPUT i: 1 i: 2 i: 3 i: 4 i: 5 i: 6 i