问题
Possible Duplicate:
R seems to multiply my data by -1
I have a simple csv file. Looks like this
x y 1 2 1 3 2 1 2 3
I created it in MS Excel, saved as csv etc.
I read it using this command
ttest<--read.csv("ttest.csv", header = TRUE)
The resulting data looks like this
x y -1 -2 -1 -3 -2 -1 -2 -3
I've opened the original csv file in a text editor and it looks like it should
回答1:
The reason is that your command:
ttest<--read.csv("ttest.csv", header = TRUE)
... has an extra dash after the <-
and R is interpreting this as a negative sign, and thus negating any numbers that it reads before it loads the data into ttest
.
In addition, there may be some confusion between read.csv()
, which is for reading comma-separated value files and read.table()
, which will read files like:
x y
1 2
1 3
2 1
2 3
... which is rather more what I think your file might have looked like originally.
来源:https://stackoverflow.com/questions/14407600/read-csv-makes-everything-negative