如何从csv读取一维数组/向量到R

时间:2023-01-08 04:21:22

I have not used R in a while, and I forgot how to do this. I am outputting about 5000 values separated by commas. I would like to import them into R and plot them just so I can see the way they are distributed.

我有一段时间没用过R,我忘记了怎么做。我输出大约5000个用逗号分隔的值。我想将它们导入R并绘制它们,以便我可以看到它们的分布方式。

File:

1,2,3,4,5,6,7,8,9,0,

Code:

x <- read.csv("output.csv", header=f, sep=",")
plot(x, axes=false, xlab="", ylab="")

When I do this I get the following error:

当我这样做时,我收到以下错误:

Error in pairs.default(data.matrix(x), ...) : object 'false' not found

What is the best way to get this result?

获得此结果的最佳方法是什么?

3 个解决方案

#1


2  

Hy

This is my solution:

这是我的解决方案:

Here is the numbers in your file (numbers.csv):

这是您文件中的数字(numbers.csv):

1,2,3,4,5,6,7,8,9


x <- read.csv(numbers.csv,header=FALSE,sep=",")

plot(1:length(x),x,axes=F)

#2


3  

As was noted in the commemt, R is case sensitive. Therefore, false does not equal FALSE, the latter being what is correct R syntax. As it does not recognize false as a boolean, is searches for an object called false which does not exist. As a note, I think it is good practice to use FALSE and not F. This makes it more explicit what you mean.

正如在纪念中所指出的,R是区分大小写的。因此,false不等于FALSE,后者是正确的R语法。由于它不能将false识别为布尔值,因此会搜索不存在的名为false的对象。作为一个注释,我认为使用FALSE而不是F是一种好习惯。这使得它更明确你的意思。

#3


0  

You can use scan function:

您可以使用扫描功能:

x <- scan("output.csv", sep=",")
plot(x, xlab="", ylab="")

#1


2  

Hy

This is my solution:

这是我的解决方案:

Here is the numbers in your file (numbers.csv):

这是您文件中的数字(numbers.csv):

1,2,3,4,5,6,7,8,9


x <- read.csv(numbers.csv,header=FALSE,sep=",")

plot(1:length(x),x,axes=F)

#2


3  

As was noted in the commemt, R is case sensitive. Therefore, false does not equal FALSE, the latter being what is correct R syntax. As it does not recognize false as a boolean, is searches for an object called false which does not exist. As a note, I think it is good practice to use FALSE and not F. This makes it more explicit what you mean.

正如在纪念中所指出的,R是区分大小写的。因此,false不等于FALSE,后者是正确的R语法。由于它不能将false识别为布尔值,因此会搜索不存在的名为false的对象。作为一个注释,我认为使用FALSE而不是F是一种好习惯。这使得它更明确你的意思。

#3


0  

You can use scan function:

您可以使用扫描功能:

x <- scan("output.csv", sep=",")
plot(x, xlab="", ylab="")