Read.csv使一切消极 [英] Read.csv makes everything negative
问题描述
可能重复:
R似乎将我的数据乘以-1
我有一个简单的csv文件。看起来像这样
I have a simple csv file. Looks like this
xy
1 2
1 3
2 1
2 3
x y 1 2 1 3 2 1 2 3
我在MS Excel中创建它,保存为csv等。
I created it in MS Excel, saved as csv etc.
我使用此命令读取它
ttest <-read.csv(ttest.csv,header = TRUE)
ttest<--read.csv("ttest.csv", header = TRUE)
生成的数据类似于
xy
-1 -2
-1 -3
-2 -1
-2 -3
x y -1 -2 -1 -3 -2 -1 -2 -3
我在文本编辑器中打开了原来的csv文件,它看起来像应该
I've opened the original csv file in a text editor and it looks like it should
推荐答案
原因是您的命令:
ttest<--read.csv("ttest.csv", header = TRUE)
...在< -
,并且R将此解释为负号,因此在将数据加载到 ttest
之前取消它读取的任何数字。
... 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
.
此外, read.csv()
之间可能存在一些混淆,用于读取逗号分隔值文件和 read.table()
,它将读取以下文件:
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.
这篇关于Read.csv使一切消极的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!