-3

I use both read.csv and read.table for importing data as following, but it`s not as numeric.can you help me whats the problem?

x<-read.csv("D:\\r-files\\mydata1.csv",header=TRUE,dec = ".")
> is.numeric(x)
[1] FALSE

or

x<-read.csv("D:\\r-files\\mydata1.txt",header=TRUE,dec = ".")
> is.numeric(x)
[1] FALSE> 
farzan
  • 1
  • 1
  • 4
    `x` is a dataframe and thus not numeric. I guess you are probably looking for `sapply(x, class)` instead. – Jaap Sep 22 '16 at 16:46
  • thank you for your answer. but I want to import my data as matrix, and I use (as.matrix(x)). There is an error that, the data is not numeric or vector. – farzan Sep 22 '16 at 17:44
  • Can you show what the top of the data or CSV look like? Can you run `sapply(x, class)` and see if it's one, some, or many columns giving you trouble? – Gregor Thomas Sep 22 '16 at 19:33
  • thanks so much. the instruction was useful, and my problem was resolved :) – farzan Sep 23 '16 at 10:47

1 Answers1

0
x <- read.csv(file="D:\\r-files\\mydata1.csv", header=TRUE, sep=",", dec = ".", stringsAsFactors = FALSE)
x <- as.matrix(x)

Hopefully this will solve your query.

Zico
  • 185
  • 12