Subsetting a list by 10 in R

50 views Asked by At

How do I subset a list like this iterating through each sublist by 10 until the end of list and sublist?

E.g.

2013_142_520
165-174
175-184

and so on till the end of the list.

$2013_142_520
 [1] 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
[28] 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
[55] 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245

$2013_142_540
 [1] 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
[28] 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
[55] 214 215 216 217 218 219 220 221 222 223

$2013_142_570
 [1] 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
[28] 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
[55] 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
[82] 242 243 244 245
1

There are 1 answers

0
JohannesNE On BEST ANSWER
lapply(your_list, function(x) split(x, ceiling(seq_along(x)/10)))