Re: Operating on every k-th element of list?
- To: mathgroup at smc.vnet.net
- Subject: [mg37124] Re: [mg37080] Operating on every k-th element of list?
- From: Bill Rowe <listuser at earthlink.net>
- Date: Thu, 10 Oct 2002 03:21:18 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 10/8/02 at 7:17 AM, siegman at stanford.edu (AES) wrote: >I want to apply a function to every k-th element of a long list and >add the result to the k+1 element. > >[Actually k = 3 and I just want to multiply myList[[k]] by a >constant (independent of k) and add the result to myList[[k+1]] for >every value of k that's divisible by 3.] If I understand what you are trying to do correctly, the following should work (f[#[[1]]+#[[2]])&/@Partition[Drop[list,k-1],2,k] Here f is the function you want applied to the k-th element