My database has 10 cases and 6 variables. I want to transpose the cases in column and save this transposition in a database.
My database has 10 cases and 6 variables. I want to transpose the cases in column and save this transposition in a database.
Use the t
function:
dados <- head(cars)
dados
speed dist
1 4 2
2 4 10
3 7 4
4 7 22
5 8 16
6 9 10
t(dados)
1 2 3 4 5 6
speed 4 4 7 7 8 9
dist 2 10 4 22 16 10
R
has several ways to save data to files. My favorite is using the write.csv
function:
write.csv(t(dados), file="dados.csv", row.names=FALSE)
In this way, the dados.csv
file will be created and can be imported into any other program that reads comma-separated data, such as Excel, for example.