0

I have the following code:

exp = list.files(pattern=glob2rx("*_input_*.txt))
int_file = lapply(exp, read.table, sep="\t", header = T)

and it returns like this:

exp
[1] "1_input_1.txt" "2_input_2.txt"
dim(int_file[[1])
[1] 2000 20
dim(int_file[[2]])
[1] 3000 20

type(int_file[[1]][1,1])
[1] "factor"

Here, the type of int_file is data frame and
the value of all columns in both two files is factor.
How I convert this factor into numeric?
I tried to run the code with 1) as.numeric(as.character(x)) 2) data.matrix(x) but, both of them did not work.

user2913161
  • 1,115
  • 2
  • 13
  • 15
  • have you tried adding `stringsAsFactors=FALSE` to the lapply function? – TWL Nov 22 '13 at 19:46
  • 2
    From the help section of `factor`: "To transform a factor ‘f’ to approximately its original numeric values, ‘as.numeric(levels(f))[f]’ is recommended and slightly more efficient than ‘as.numeric(as.character(f))’." – Justin Nov 22 '13 at 19:47

0 Answers0