gpt4 book ai didi

r - 创建一个包含一行和多列的数据框

转载 作者:行者123 更新时间:2023-12-02 03:14:40 24 4
gpt4 key购买 nike

我想创建一个 12 列和 1 行的数据框。我有这个数据:

Tissues <-
[1] "ova" "testes" "optic_lobe" "retina" "suckers"
[6] "subesophageal_brain" "Supraesophageal_brain" "skin" "stage15tissues" "axial_nerve_corde"
[11] "posterior_salivary_gland" "viscera"
reads <-
[1] 22444744 30671024 22648756 24002307 26438055 48999389 60168243 30172728 26812536 23359754 24038817 25570689

我想创建这个:

       tissue1 tissue2 tissue3 tissue4 tissue5 tissue6 etc..
reads 1 2 3 4 5 6

我已经尝试过:

df <- data.frame(matrix(ncol = 12, nrow = 1))
x <- TESSUTI
colnames(df) <- x

但是如何将读数添加到每列?

有人可以帮助我吗?

最佳答案

有一个可重现的示例很有帮助,我们可以轻松复制和粘贴。

这是一个解决方案:

##Your input data
tissues <- letters[1:12]
reads <- rnorm(n = 12,mean = 250000,sd = 1000)

##Put the reads into one row of a matrix, then convert to dataframe
data <- data.frame(matrix(nrow = 1,data = reads))

##set the colnames to match your tissue, and the reads row to have a reads name
colnames(data) <- tissues
rownames(data) <- 'reads'

print(data)
a b c d e f g h i j k l
reads 250813 250376 250178 251138 251033 249945 250165 248150 251168 251193 249658 250621

关于r - 创建一个包含一行和多列的数据框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56499973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com