I have an excel file with 2 columns (1st column with headers & 2nd with data) and I'm trying it to transpose it(1st row with headers & 2nd with data). For some reason my code is only working for the data with >= 2rows.
Input Excel:
Expected Output:
Code:
df <- df_customer_upload() # original excel file
df <- t(df_customer_upload()) # Transposed excel file, in matrix format
colnames(df) <- (df[1, ]) # Copies 1st row to the header
df <- df[-1,] # after copying 1st row as header, deletes the 1st row
View(df)
Any help would be appreciated. Thanks in advance!!