def group_events(events):
    """
    Groups events by ID, station, instrument and channel code.
    """

    grouped = []
    grouped_ids = []

    for i, e in enumerate(events):

        if i in grouped_ids:
            continue

        group_tag = e['id'] + e['station'] + e['instrument']
        current_group = [e]
        grouped_ids.append(i)

        for j in range(i + 1, len(events)):

            if j in grouped_ids:
                continue

            e2 = events[j]
            e2_tag = e2['id'] + e2['station'] + e2['instrument']
            if e2_tag == group_tag:
                grouped_ids.append(j)
                current_group.append(e2)

        grouped.append(current_group)

    return grouped