Q:

Merge two list components

I have a big list, but micro example would be like the following: 
A <- c("A", "a", "A", "a", "A")
B <- c("A", "A", "a", "a", "a")
C <- c(1, 2, 3, 1, 4) 
mylist <- list(A=A, B=B, C= C)

expected output is merge A with B so that each component will look like AB
AA, aA, Aa, aa, Aa

better should be sorted, upper case is always first 
AA, Aa, Aa, aa, Aa

Thus new list or matrix should have two columns or rows:
AA, Aa, Aa, aa, Aa
1,   2, 3,   1, 4

Now I want calculate average of C based on class - "AA", "Aa", and "aa"
Looks simple but I could not figure out easily.

A:

> (ab <- paste(A, B, sep="") )
[1] "AA" "aA" "Aa" "aa" "Aa"
> (ab <- paste(A, B, sep="") )  # the joining step
[1] "AA" "aA" "Aa" "aa" "Aa"
> (ab <- sub("([a-z])([A-Z])", "\\2\\1", ab) ) # swap lowercase uppercase
[1] "AA" "Aa" "Aa" "aa" "Aa"

> rbind(ab, C)                  # matrix
   [,1] [,2] [,3] [,4] [,5]
ab "AA" "Aa" "Aa" "aa" "Aa"
C  "1"  "2"  "3"  "1"  "4" 
> data.frame(alleles=ab, count=C)  # dataframes are lists
  alleles count
1      AA     1
2      Aa     2
3      Aa     3
4      aa     1
5      Aa     4

