I'm having trouble relocating rows from my .csv table. Here's an example:
Let's say I have an 8x2 table and I want to turn it into a 4x3 table, using the matchid as a reference. Example:
matchid | playerid
1 | 23
1 | 15
1 | 12
1 | 65
1 | 21
1 | 45
1 | 123
1 | 11
Expected:
matchid | playerid.x | playerid.y
1 | 23 | 21
1 | 15 | 45
1 | 12 | 123
1 | 65 | 11
I've tried using a function to traverse my table and fill in a new array:
collectData = function (data){
matriz = matrix()
count = 1
col = 1
for(i in 1:nrow(data)){
if(count < 4){
matriz[i,col] = data[i,2]
count = count + 1
}
if (count == 4) {
count = 0
col = col + 1
}
}
return(matriz)
}
Edit :
The CSV table has 3 columns and n rows, I want to split it by rows in half then put the second half aside from the first half
x
andy
) or is there another criteria to identifyx
's values fromy
's ? (When you say "using the matchid as a reference" that would mean that its value is what determine whether to assignplayerid
to x or y but your example says otherwise since allmatchid
values equal to 1)