0
データセットを転置したいと考えています。情報を失うことなくRにデータを転記するには?
Pretext:QIIME2は、 'Feature.ID'(本質的に細菌種)が行で、Sitesが列であり、セルの値が豊富になるように出力します。生物多様性などの多くのRパッケージでは、サイトの行と種が列である必要があるため、データの転置を検討しています。
library(tidyverse)
Ftable <- read_tsv('table.feature-table_biom.txt', col_names = TRUE, skip = 1) #opens my QIIME2 file, removing the top line
names(Ftable)[names(Ftable)=="#OTU ID"] <- "Feature.ID" #Renames the species column
Ftable <- cbind(Ftable, "observation"=1:nrow(Ftable)) #adds an indexing column 'observation' so that I can later remove the column containing the species names as they are complex and I do not wish to type them out
Ftable <- Ftable %>% select(observation, everything()) #Moves observation to the front
OtuOb <- Ftable
OtuOb <- as.tibble(OtuOb)
write_tsv(OtuOb, "OtuToObservationReference.tsv") #These 3 lines save a reference so I can look to see which observations align to which species
Ftable <- Ftable[,-2] #removes 'Feature.ID' column so that the observation column shows the species
Ftable <- t(Ftable) #I have been trying to get this to work but it doesnt
Ftable <- as.tibble(Ftable)
write_tsv(Ftable, "Ftable.tsv")
それは私は、彼らがその種の存在量に一致する方法見ての方法がないことを意味する(オリジナルのトップに沿って)サンプルの参照を削除し転置。移調前
を私はおそらく(いくつかの混乱があると思います私の転置データにカラム名として元のロー名を表示したい場合は –
オブジェクトに行名を割り当てる(例えば、 'Ftable_rownames < - rownames(Ftable)'、転置して、保存したベクトルをcolnamesに代入する( 'colnames(Ftable)< - Ftable_rownames') – Phil
大丈夫とても混乱しているようです。基本的には逆の方法で列名を保持し、それらを適切な行に割り当てます。 –