Warning: include(../../statistics/statistics_top.php) [function.include]: failed to open stream: No such file or directory in /home/content/33/10959633/html/r/transpose.php on line 21
Warning: include() [function.include]: Failed opening '../../statistics/statistics_top.php' for inclusion (include_path='.:/usr/local/php5_3/lib/php') in /home/content/33/10959633/html/r/transpose.php on line 21
R Transpose Matrix Example
t(x) function will transpose a matrix or data frame. If it is a vector, it will be transposed to a one row matrix.
Following is a csv file example transpose.csv.
>x <- read.csv("transpose.csv",header=T,sep=",",dec=".");
>x <- t(x)
However, if you want to transpose the matrix as well as revise some elements, the above code can not do that.
Following R code can read in a file into matrix, transpose it and then write to an output file. It do that by reading through
each element, such that you may revise the elements as you like, e.g. substring or do some calculation during the process.
The result file is:
Download the csv file and the R source code:
Data File
R Source Code File
Output Data File