2

I would to create a data frame with 12 columns and one row. I have this data:

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

I would to create this:

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

I've tried:

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

but how can I add the reads to each columns?

anyone could help me?

1
  • 1
    Just do setNames(as.data.frame.list(reads)), Tissues) Commented Jun 7, 2019 at 19:22

3 Answers 3

3

Helpful to have a reproducible example that we can easily copy and paste.

Here is a solution:

##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
Sign up to request clarification or add additional context in comments.

Comments

1
df <- setNames(data.frame(t(c(22444744, 30671024, 22648756, 24002307, 26438055, 48999389, 60168243, 30172728, 26812536, 23359754, 24038817, 25570689))),
         c("ova", "testes", "optic_lobe", "retina","suckers" , "subesophageal_brain", "Supraesophageal_brain",
           "skin", "stage15tissues", "axial_nerve_corde", "posterior_salivary_gland","viscera"))
rownames(df) <- "read"
df

Most of it in 1 line, which results in:

          ova   testes optic_lobe   retina  suckers subesophageal_brain Supraesophageal_brain     skin stage15tissues axial_nerve_corde posterior_salivary_gland  viscera
read 22444744 30671024   22648756 24002307 26438055            48999389              60168243 30172728       26812536          23359754                 24038817 25570689

Comments

1

You can create a data frame with two vector and spread as columns one of them using spread() from tidyr

library(tidyr)

# data
Tissues <- c( "ova", "testes", "optic_lobe", "retina", "suckers",
   "subesophageal_brain","Supraesophageal_brain","skin",
   "stage15tissues", "axial_nerve_corde", "posterior_salivary_gland", "viscera")                 

reads <-c(22444744, 30671024, 22648756, 24002307, 26438055, 48999389,
          60168243, 30172728, 26812536, 23359754, 24038817, 25570689)


df <- *emphasized text*data.frame(Tissues, reads) %>%
  spread(Tissues, reads)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.