[R] systematically matching the numbers in two sequences
I am having trouble writing a code for matching two pairs of sequences with differing lengths: for example sequence1= 1,2,3,4,5,6,7 sequence2=1,2,3,4,5,6,7,8,9,10 I want to create several new pairs of sequences in several dataframes such that: 1st dataframe is 1,10 (start of sequence1, end of sequence 2) 2nd dataframe is 1, 9 2, 10 3rd dataframe is 1, 8 2, 9 3, 10 etc etc. I realise this may involve a complicated loop and am really struggling to make a start on it. -- View this message in context: http://www.nabble.com/systematically-matching-the-numbers-in-two-sequences-tp20855728p20855728.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] systematically matching the numbers in two sequences
Try this: s1 <- 1:7 s2 <- 1:10 lapply(seq(length(s1)), function(i)cbind(head(s1, i), tail(s2, i))) On Fri, Dec 5, 2008 at 1:44 PM, emj83 <[EMAIL PROTECTED]> wrote: > > I am having trouble writing a code for matching two pairs of sequences with > differing lengths: > > for example sequence1= 1,2,3,4,5,6,7 sequence2=1,2,3,4,5,6,7,8,9,10 > > I want to create several new pairs of sequences in several dataframes such > that: > 1st dataframe is 1,10 (start of sequence1, end of sequence 2) > 2nd dataframe is 1, 9 > 2, 10 > > 3rd dataframe is 1, 8 >2, 9 >3, 10 > > etc etc. > > I realise this may involve a complicated loop and am really struggling to > make a start on it. > -- > View this message in context: > http://www.nabble.com/systematically-matching-the-numbers-in-two-sequences-tp20856673p20856673.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] systematically matching the numbers in two sequences
I am having trouble writing a code for matching two pairs of sequences with differing lengths: for example sequence1= 1,2,3,4,5,6,7 sequence2=1,2,3,4,5,6,7,8,9,10 I want to create several new pairs of sequences in several dataframes such that: 1st dataframe is 1,10 (start of sequence1, end of sequence 2) 2nd dataframe is 1, 9 2, 10 3rd dataframe is 1, 8 2, 9 3, 10 etc etc. I realise this may involve a complicated loop and am really struggling to make a start on it. -- View this message in context: http://www.nabble.com/systematically-matching-the-numbers-in-two-sequences-tp20856673p20856673.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.