# Taking parts of a list. Especially multiple chuncks of a list

I would like to gather parts of a list and compile them to a new list. for example the list is: {1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5...}. I need to able to take the 3rd through the 5th for each value such that the new list will be {1,1,1,2,2,2,3,3,3,...}.

My data out put is setup that the first column is time, second is wavelength, third is signal data. Its setup that it takes one spectrum at every time point, so the first column ends up being the same time value for the entire wavelength portion. I only need a portion of the spectrum, so I need to only select the cells I need.

What I've tried:data[[25;;50, 1]] resulting in only pulling the first set up time points from 25 to 50. I can't figure out how to get the 2nd, 3rd,... time point. The wavelength section has 2048 entries, so my first guess would be to do something like: t1 = Downsample[data[[1, 1 ;;, 1]], 2048] n = Range[0, Length[t1]] data[[n*2048+(25;;50),1]]

• list // Partition[#, 5] & // Map[Drop[#, -2] &] // Flatten Apr 17, 2021 at 4:14
• list = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5};Join @@ Partition[list, 5][[All, 3 ;; 5]]?
– kglr
Apr 17, 2021 at 4:17
• .. or Join @@ Split[list][[All, 3 ;; 5]]?
– kglr
Apr 17, 2021 at 4:18

list = {1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5};

SequenceCases[list, {a_, a_ ,a_ ,_ ,_} -> Sequence[a, a, a]]


{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5}

list = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5};

Splice@#[[;; 3]] & @@@ Outer[List, Split[list], 1]

(*{1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5}*)


For

list = {1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5,
5, 5, 5, 5};


you can use Split and Catenate

Catenate[#[[3 ;; 5]] & /@ Split[list]]


yields: {1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5}