how to write column name for a dataframe in R studio?

i try to name the dataframe coloumns with some names, but im unable to name the columns .. I tried with al conventional methods of naming like use of colnames() colnames =(), if some one know it please help me

GC_content7 <- function(fasta_file){
  library("seqinr")
  
  x <- read.fasta(file = fasta_file)
  tt<-function(x){
    res<-GC(x)
    val=round(res,4)
    return(val)
  }
  
  f_res<-lapply(x,tt)
  s=data.frame(f_res)
  w=t(s)
  return(w)

the t() / transpose of a data.frame is not a data.frame but a matrix, so watch out for that. your w is a matrix.


(tiris <- t(head(iris)))

colnames(tiris) <- letters[1:6]
tiris

tiris2 <- as.data.frame(t(head(iris)))
names(tiris2) <- letters[1:6]
tiris2

thank you sir for the answer

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.