1

I imported a dataset with no column headings, and I'm trying to label the columns for convenience. I've used R quite a bit before, so I'm confused as to why this code isn't working:

library(mosaic)
`0605WindData` <- read.csv("~/pathnamehere/0605WindData.txt", header=F)
Station = 0605WindData[,1]
Error: unexpected symbol in "Station = 0605WindData"

I swear I have experience with R (albeit I'm a bit out of practice), but I seem to be stuck on something pretty simple. I know I've used this select column command before. Suggestions?

4

2 回答 2

4

子集时您忘记引用对象名称:

> `0605WindData` <- data.frame(A = 1:10, B = 1:10)
> `0605WindData`[,1]
 [1]  1  2  3  4  5  6  7  8  9 10

正如 Roman 所指出的,对象名称不应该以数字开头。您的read.csv()行仅起作用,因为您反引号引用了对象名称。您现在必须在每一行代码中继续引用该对象,因为您为该对象使用了非标准名称。省去一些麻烦并更改您分配输出的对象的名称read.csv()

于 2013-06-07T15:52:24.837 回答
0
    `0605WindData` <- read.csv("~/pathnamehere/0605WindData.txt", header=F)
    Station = 0605WindData[,1]

而不是使用引号作为带有字母的变量开始变量名称,例如

     winddata060 <- read.csv("~/pathnamehere/0605WindData.txt", header=F)

现在选择所需的变量名

     Station = winddata060[,1]
于 2013-06-07T19:06:48.350 回答