Reputation: 169
I'm new to R and this is a very simple problem that I can't seem to solve... So I want to make a list which contains A1~A12, B1~B12, C1~C12, D1~D12, E1~E12, F1~F12, G1~G12, and H1~H12. Something like below...
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8"
[21] "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4"
[41] "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12"
[61] "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8"
[81] "G9" "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12"
I tried using rep... or creating a vector of LETTERS[1:8] and a separate vector of c(1:12) and tried combining them together... but I haven't been very successful.
Thanks in advance!
Additional Question somewhat related...
So after I make this, I want to compare this to another list. The other list may look something like this:
[1] "A1" "A2" "A3" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9"
[21] "B10" "B11" "B12" "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" "D5"
[41] "D6" "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12" "F1"
[61] "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9"
[81] "G10" "G11" "G12" "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12"
It's not very clear but this list is missing "A4". By comparing this one to the one I have created that has all 96 elements, I want to know which element is missing. I tried using functions like intersect and setdiffer.. but they don't compare the lists, element by element.
Upvotes: 0
Views: 1512
Reputation: 52687
Here is an alternative. The key is the each
argument to rep
and using it for one of the elements but not the other:
paste0(rep(LETTERS[1:8], each=12), rep(1:12, 8))
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12" "B1" "B2"
[15] "B3" "B4" "B5" "B6" "B7" "B8" "B9" "B10" "B11" "B12" "C1" "C2" "C3" "C4"
[29] "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12" "D1" "D2" "D3" "D4" "D5" "D6"
[43] "D7" "D8" "D9" "D10" "D11" "D12" "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8"
[57] "E9" "E10" "E11" "E12" "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10"
[71] "F11" "F12" "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" "G10" "G11" "G12"
[85] "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12"
Upvotes: 6
Reputation: 44565
> e <- expand.grid(1:12,LETTERS[1:8])
> paste0(e[,2],e[,1])
[1] "A1" "A2" "A3" "A4" "A5" "A6" "A7" "A8" "A9" "A10" "A11" "A12"
[13] "B1" "B2" "B3" "B4" "B5" "B6" "B7" "B8" "B9" "B10" "B11" "B12"
[25] "C1" "C2" "C3" "C4" "C5" "C6" "C7" "C8" "C9" "C10" "C11" "C12"
[37] "D1" "D2" "D3" "D4" "D5" "D6" "D7" "D8" "D9" "D10" "D11" "D12"
[49] "E1" "E2" "E3" "E4" "E5" "E6" "E7" "E8" "E9" "E10" "E11" "E12"
[61] "F1" "F2" "F3" "F4" "F5" "F6" "F7" "F8" "F9" "F10" "F11" "F12"
[73] "G1" "G2" "G3" "G4" "G5" "G6" "G7" "G8" "G9" "G10" "G11" "G12"
[85] "H1" "H2" "H3" "H4" "H5" "H6" "H7" "H8" "H9" "H10" "H11" "H12"
Upvotes: 3