I have a file where a data structure containing 6 columns is stored side by side. That means I have n times 6 columns stored in a flat file.
Basically, I want to rearrange the data in a form that I only have a data.frame containing 6 columns but appending all the data from the file to the end of the first 6 columns.
Row 1V1 1V2 1V3 1V4 1V5 1V6 2V1 2V2 2V3 2V4 2V5 2V6 3V1...
1
2
The result should look like that moving data from 2V1-2V6 to the end of 1V1-1V6
Row V1 V2 V3 V4 V5 V6
1-1
1-2
2-1
2-2
I looked up some code snippets and could load the data into a data frame with all the vectors. Then I tried to create n dataframes containing always the repeating data structures. Then I tried to combine the single dataframes to a final one but it does not work.
df<-read.table("test.txt",header = FALSE, sep = ";", skip = 2)
columnmax=as.integer(ncol(df)/6)
dfnew <- vector(mode="list",length=columnmax)
for ( i in 1:columnmax) {
start<-((i-1)*6+1)
end<-(i*6)
dfnew[[i]]<-df[,start:end]
}
y <- do.call(rbind, dfnew)
RESULT: Error in match.names(clabs, names(xi)) : names do not match previous names
I used the list mode because I didnt get it working to separate the dataframe otherwise. But it seems now to me that it makes the rbind to a problem because the "columnnames" are not identically. I havent not even an idea how to change the column names because its not a matrix in R termini but a list. I am sure there must be a much simpler way to do what I want but I am just beginning in R and not familiar with the many different concepts of data types.
EDIT: DATA
structure(list(V1 = NA, V2 = NA, V3 = NA, V4 = NA, V5 = NA, V6 = NA,
V7 = NA, V8 = NA, V9 = NA, V10 = NA, V11 = NA, V12 = NA,
V13 = structure(1L, .Label = "1,20101E+27", class = "factor"),
V14 = structure(1L, .Label = "05.07.2010 14:50", class = "factor"),
V15 = structure(1L, .Label = "ADMINISTRATOR", class = "factor"),
V16 = 1L, V17 = NA, V18 = NA, V19 = structure(1L, .Label = "1,20101E+27", class = "factor"),
V20 = structure(1L, .Label = "05.07.2010 14:50", class = "factor"),
V21 = structure(1L, .Label = "ADMINISTRATOR", class = "factor"),
V22 = 1L, V23 = NA, V24 = NA, V25 = structure(1L, .Label = "1,20101E+27", class = "factor"),
V26 = structure(1L, .Label = "05.07.2010 14:50", class = "factor"),
V27 = structure(1L, .Label = "ADMINISTRATOR", class = "factor"),
V28 = 1L, V29 = NA, V30 = NA, V31 = structure(1L, .Label = "1,20101E+27", class = "factor"),
V32 = structure(1L, .Label = "05.07.2010 14:50", class = "factor"),
V33 = structure(1L, .Label = "ADMINISTRATOR", class = "factor"),
V34 = 1L, V35 = NA, V36 = NA, V37 = NA, V38 = NA, V39 = NA,
V40 = NA, V41 = NA, V42 = NA, V43 = NA, V44 = NA, V45 = NA,
V46 = NA, V47 = NA, V48 = NA, V49 = NA, V50 = NA, V51 = NA,
V52 = NA, V53 = NA, V54 = NA, V55 = NA, V56 = NA), .Names = c("V1",
"V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11",
"V12", "V13", "V14", "V15", "V16", "V17", "V18", "V19", "V20",
"V21", "V22", "V23", "V24", "V25", "V26", "V27", "V28", "V29",
"V30", "V31", "V32", "V33", "V34", "V35", "V36", "V37", "V38",
"V39", "V40", "V41", "V42", "V43", "V44", "V45", "V46", "V47",
"V48", "V49", "V50", "V51", "V52", "V53", "V54", "V55", "V56"
), row.names = 1L, class = "data.frame")