seq

Generate a sequence of characters from 'A'-'Z'

为君一笑 提交于 2019-11-29 01:01:52
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) Use LETTERS and letters (for uppercase and lowercase respectively). Use the code you have with letters and/or LETTERS : > LETTERS[seq( from = 1, to = 10 )] [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" > letters[seq( from = 1, to = 10 )] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" Just use the predefined variables letters and LETTERS . And for completeness, here it something using seq : R> rawToChar(as.raw(seq(as.numeric(charToRaw('a')),

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

倖福魔咒の 提交于 2019-11-28 18:01: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... 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 range from c1 to c2 in whatever character sequence is used internally. For characters with code points

What are examples of when seq_along works, but seq produces unintended results?

吃可爱长大的小学妹 提交于 2019-11-28 16:03:12
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 unintended consequences if it is called with just one argument intending this to be taken as along.with : it is much better to use seq_along in that case. This should make the difference clear. Basically, seq() acts like seq_along() except when passed a vector of length 1, in which case it acts like seq_len() . If this ever once bites you, you'll never use seq

creating sequence of dates for each group in r

别说谁变了你拦得住时间么 提交于 2019-11-28 12:27:01
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 is: Error: incompatible size (453), expecting 1 (the group size) or 1 Can you please suggest some

How to produce cartesian product in bash?

心不动则不痛 提交于 2019-11-28 12:05:09
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? 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: $ echo {1..5}+{a,b,c} 1+a 1+b 1+c 2+a 2+b 2+c 3+a 3+b 3+c 4+a 4+b 4+c 5+a 5+b 5+c A shorter (but hacky)

Convert Java List to Scala Seq

对着背影说爱祢 提交于 2019-11-28 09:44:05
I need to implement a method that return 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<String> columnNames() { List<String> a = new ArrayList<String>(); a.add("john"); a.add("mary"); Seq<String> b = (scala.collection.Seq<String>) a; return b; } But scala.collection.JavaConverters doesn't seem to offer the possibility to convert as a Seq . JavaConverters is what I needed to solve this. import scala.collection.JavaConverters; public Seq<String> convertListToSeq(List<String> inputList) {

F# equivalent of LINQ Single

偶尔善良 提交于 2019-11-28 09:39:51
问题 Ok, so for most LINQ operations there is a F# equivalent. (Generally in the Seq module, since Seq= IEnumerable) I can't find the equiv of IEmumerable.Single , I prefer Single over First (which is Seq.find), because it is more defensive - it asserts for me the state is what I expect. So I see a couple of solutions (other than than using Seq.find). (These could be written as extension methods) The type signature for this function, which I'm calling only, is ('a->bool) -> seq<'a> -> 'a let only

Inconsistency with Clojure's sequences?

感情迁移 提交于 2019-11-28 07:15:00
问题 Clojure: 1:13 user=> (first (conj '(1 2 3) 4)) 4 1:14 user=> (first (conj [1 2 3] 4)) 1 ; . . . 1:17 user=> (first (conj (seq [1 2 3]) 4)) 4 I understand what is going on, but should this work differently? 回答1: Documentation for conj (from clojure.org): conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type. It's more efficient to "add" elements to the end of a vector, while it's

Convert Java List to Scala Seq

会有一股神秘感。 提交于 2019-11-27 22:03:05
问题 I need to implement a method that return 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<String> columnNames() { List<String> a = new ArrayList<String>(); a.add("john"); a.add("mary"); Seq<String> b = (scala.collection.Seq<String>) a; return b; } But scala.collection.JavaConverters doesn't seem to offer the possibility to convert as a Seq . 回答1: JavaConverters is what I needed to solve

Generate a sequence of characters from 'A'-'Z'

£可爱£侵袭症+ 提交于 2019-11-27 15:32:52
问题 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) 回答1: Use LETTERS and letters (for uppercase and lowercase respectively). 回答2: Use the code you have with letters and/or LETTERS : > LETTERS[seq( from = 1, to = 10 )] [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" > letters[seq( from = 1, to = 10 )] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" 回答3: Just use the predefined variables letters