Read.csv makes everything negative [duplicate]

会有一股神秘感。 提交于 2019-12-24 01:52:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!