Read the text file in R and convert it to a character object

I am reading a text file similar to this in R 2.10.0

248585_at   250887_at   245638_s_at AFFX-BioC-5_at
248585_at   250887_at   264488_s_at 245638_s_at AFFX-BioC-5_at  AFFX-BioC-3_at  AFFX-BioDn-5_at
248585_at   250887_at

Using the Clusters <-read.delim command ("test", September = "\ t", filling = TRUE, then heading = FALSE)

Now I have to pass each line in this file to the BioConductor function, which accepts only character vectors as input. My problem is that using "as.character" in this "clusters" object turns everything into numeric strings.

> clusters[1,]
         V1        V2          V3             V4 V5 V6 V7
1 248585_at 250887_at 245638_s_at AFFX-BioC-5_at         

But

> as.character(clusters[1,])
[1] "1" "1" "2" "3" "1" "1" "1"

Is there a way to keep the original names and put them in a character vector?

Maybe this helps: my "clusters" object, specified by read.delim, is of type "list".

Many thanks: -)

Federico

+3
2

. , as.is=TRUE:

clusters <- read.delim("test", sep="\t", fill=TRUE, header=FALSE, as.is=TRUE)

, - :

x <- readLines("test")
xx <- strsplit(x,split="\t")
xx[[1]] # xx is a list
# [1] "248585_at"      "250887_at"      "245638_s_at"    "AFFX-BioC-5_at"
+6

, , , .

df[1,] data.frame, , unlist -, , :

> df <- data.frame(a=LETTERS[1:10], b=LETTERS[11:20], c=LETTERS[5:14])
> df[1,]
  a b c
1 A K E
> as.character(df[1,])
[1] "1" "1" "1"
> as.character(unlist(df[2,]))
[1] "B" "L" "F"

, data.frame matrix :

m <- as.matrix(df)
> as.character(m[2,])
[1] "B" "L" "F"

data.frame, stringsAsFactors=TRUE , :

clusters <- read.delim("test", sep="\t", fill=TRUE, header=FALSE,
                       stringsAsFactors=FALSE)

, , , , , data.frame . , stringsAsFactors=FALSE :

df <- data.frame(a=LETTERS[1:10], b=LETTERS[11:20],
                 c=LETTERS[5:14], stringsAsFactors=FALSE)
> as.character(df[1,])
[1] "A" "K" "E"
+1

Source: https://habr.com/ru/post/1725049/


All Articles