我正在编写一个函数并且遇到了一些问题。我的函数没有创建新变量,运行后没有错误,也没有变化,就好像我从未运行过它一样。函数之前的代码工作得很好,如果我直接通过代码传递参数(绕过代码的函数方面),它运行完美。
你觉得我有什么遗漏吗?我已经看了两天了,已经没有想法可以尝试了。任何建议将不胜感激!
path <- "C:/Documents/Data"
readFile <- paste(path,"/opps.csv",sep="")
oppsQty <- read.csv(file=readFile,sep=",")
oppsQty$Line.Created.date <- as.Date(as.character(oppsQty$Line.Created),
"%m/%d/%Y")
opQty002.0084.01 <- oppsQty[oppsQty$Part=="002-0084-01",]
productNumberData <- function(nameNum,prodNum){
# CREATING YEAR VARIABLE #
year2009 <- ifelse((nameNum$Line.Created.date <=
as.Date("12/30/2009","%m/%d/%Y")),"2009","0")
year2010 <- ifelse((nameNum$Line.Created.date >
as.Date("12/30/2009","%m/%d/%Y")&
nameNum$Line.Created.date <=
as.Date("12/30/2010","%m/%d/%Y")),"2010",year2009)
year2011 <- ifelse((nameNum$Line.Created.date >
as.Date("12/30/2010","%m/%d/%Y")&
nameNum$Line.Created.date <=
as.Date("12/30/2011","%m/%d/%Y")),"2011",year2010)
nameNum$line.YEAR <- ifelse((nameNum$Line.Created.date >
as.Date("12/30/2011","%m/%d/%Y")&
nameNum$Line.Created.date <=
as.Date("12/30/2012","%m/%d/%Y")),"2012",year2011)
}
productNumberData(opQty002.0084.01,"002-0084-01")
#opQty002.0084.01$line.YEAR does not exist