I'm new to R, and I have a data file in txt format like this:
我是R的新手,我有一个txt格式的数据文件,如下所示:
17.72
15.29
15.18
15.58
16.52
28.77
26.08
23.69
14.76
13.90
14.37
18.02
20.67
23.72
13.66
I wish to read it into R and draw a line with all data points having a 'o' as dot so I:
我希望将它读入R并绘制一条线,其中所有数据点都有一个'o'作为点,所以我:
y<-read.table('~/my.data')
length(y)
It prints "1". I wish that y is an array of 31 elements as I have in the file. How can I make it, and then plot in a graph, with x-axis having 1-31?
它打印“1”。我希望y是一个包含31个元素的数组,就像我在文件中一样。我怎样才能制作它,然后用图表绘制,x轴为1-31?
Thanks!
谢谢!
1 个解决方案
#1
1
With y<-read.table('~/my.data')
, R
reads your data as a data.frame
. Since it does not have a header
, the column name is assigned as V1
.
使用y <-read.table('〜/ my.data'),R将您的数据作为data.frame读取。由于它没有标题,因此列名称被指定为V1。
Below will tell you number of items:
以下将告诉您项目数量:
length(y$V1)
Finally you can plot it with:
最后你可以用它绘制它:
plot(y$V1)
#1
1
With y<-read.table('~/my.data')
, R
reads your data as a data.frame
. Since it does not have a header
, the column name is assigned as V1
.
使用y <-read.table('〜/ my.data'),R将您的数据作为data.frame读取。由于它没有标题,因此列名称被指定为V1。
Below will tell you number of items:
以下将告诉您项目数量:
length(y$V1)
Finally you can plot it with:
最后你可以用它绘制它:
plot(y$V1)