2

transpose of the data with tidy verse. however i am not looking to use transpose function. i am trying to use tidy verse.i could perform this in small samples but the data of genes here is large.so i could not succeed. The data has 9524 rows and 10 columns however i need to swap the rows with the column such that the shape of the data becomes 10 rows and 9524 columns which i am struggling with.

The data. mat

  Sample1 Sample2 Sample3 Sample4 Sample5 Sample6 Sample7 Sample8 Sample9 
    <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>   <dbl>    
1    1.49   0.414    1.15    1.26    2.35   0.730    1.04   0.379   0.395     
2    3.63   3.85     1.78    3.42    2.16   2.41     3.23   3.52    3.86      
3    5.09   5.35     5.25    5.05    5.14   5.54     5.93   4.86    5.22      
4    5.48   5.88     6.29    5.81    7.41   5.90     6.39   6.10    5.25      
5    4.94   6.07     5.47    5.73    6.00   5.62     5.80   6.60    6.55      
6    5.75   6.27     6.68    6.48    7.02   5.47     5.85   5.51    5.77      
7
to 
9524

The data after the conversion using tidy verse should look like the below format
            1       2       3       4      5      and so on  
sample 1    1.49     3.63    5.09   5.48    4.94     
sample 2    0.414    3.85    5.35   5.88    6.07
sample 3    1.15     1.78    5.25   6.29    5.47   
sample 4    1.26     3.42    5.05   5.81    5.73
 etc  




mat<- gather(mat,position,value)

str(mat)
'data.frame':   95240 obs. of  2 variables:
 $ position: chr  "Sample 1" "Sample 1" "Sample 1" "Sample 1" ...
 $ value   : num  1.49 3.63 5.09 5.48 4.94 ...

i know its not correct. any help will be appreciated.

str(mat)
Classes ‘tbl_df’, ‘tbl’ and 'data.frame':   9524 obs. of 9 variables:
 $ Sample1 : num  1.49 3.63 5.09 5.48 4.94 ...
 $ Sample2 : num  0.414 3.853 5.348 5.877 6.073 ...
 $ Sample3 : num  1.15 1.78 5.25 6.29 5.47 ...
 $ Sample4 : num  1.26 3.42 5.05 5.81 5.73 ...
 $ Sample5 : num  2.35 2.16 5.14 7.41 6 ...
 $ Sample6 : num  0.73 2.41 5.54 5.9 5.62 ...
 $ Sample7 : num  1.04 3.23 5.93 6.39 5.8 ...
 $ Sample8 : num  0.379 3.517 4.864 6.099 6.598 ...
 $ Sample9 : num  0.395 3.863 5.216 5.248 6.553 ...
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Aparna Prasad
  • 91
  • 1
  • 6

0 Answers0