仅保留某些列.eval(expr,envir,enclos)中的错误:找不到对象

时间:2014-12-30 19:14:27

标签: r dataframe knitr sweave

当我运行以下代码块时,我收到错误:eval中的错误(expr,envir,enclos):找不到对象'x'。它指的是最后一行。我对R的这一部分有点新意,不知道出了什么问题。阅读有关data.frame的文档后,语法似乎正确,但我现在不太确定。

我正在使用Windows 8计算机并使用Sweave和knitr在RStudio中运行代码。

<<read.file,message=FALSE>>=
library(RCurl)
library(xtable)
#READ DATA
con <- getURL("URLforCSVdownloadHere")
x <- read.csv(textConnection(con),stringsAsFactors=FALSE)
@

<<clean.file,message=FALSE>>=
#REPLACE SYMBOLS
x <- as.data.frame(sapply(x,function(x) {gsub("\\$", "\\\\$", x)}),stringsAsFactors=FALSE)
x <- as.data.frame(sapply(x,function(x) {gsub("\\%", "\\\\%", x)}),stringsAsFactors=FALSE)
x <- as.data.frame(sapply(x,function(x) {gsub("\\&", "\\\\&", x)}),stringsAsFactors=FALSE)
x <- as.data.frame(sapply(x,function(x) {gsub("\\#", "\\\\#", x)}),stringsAsFactors=FALSE)
x <- as.data.frame(sapply(x,function(x) {gsub("\\^", "\\\\^", x)}),stringsAsFactors=FALSE)
x <- as.data.frame(sapply(x,function(x) {gsub("\\_", "\\\\_", x)}),stringsAsFactors=FALSE)
#RENAME COLUMNS
colnames(x)[2] <- "Student.Id"
@

<<project.list,include=FALSE>>=
spx <- x[,c(1,9,3,2,10)]

#split
spx <- split(spx,spx$Section)

#row.num func
rnum <- function(x){as.numeric(rownames(x))}

#table func
printProjectList <- function(project.list,i){
  project.list <- project.list[[i]]
  row.names(project.list)<-NULL
  color.rows <- seq(1, nrow(project.list), by=2) 
  print(xtable(project.list, align=c("c","p{2.0cm}","p{1in}","c","p{1in}","p{2in}")), booktabs=TRUE, 
   add.to.row = list(pos = as.list(color.rows), command = rep("\\rowcolor[gray]{0.9}",length(color.rows))))
}
@

0 个答案:

没有答案