以下代码有效:
tdata <- read.table(filename, header=T, colClasses=c(rep("character", 6), rep("numeric", 3)))
names(tdata) <- c("Date", "City", "Key", "Number", "Count")
indata <- transform(tdata, Date = as.Date(Date), Sum = Number*Count)
dd <- ddply(indata, .(paste(Key, substr(City,1,3), sep=","), summarize, total=sum(Sum))
并制作
1 KEY1,NEW 3456
但以下内容:
tdata <- read.table(filename, header=T, colClasses=c(rep("character", 6), rep("numeric", 3)))
names(tdata) <- c("Date", "City", "Key", "Number", "Count")
indata <- transform(tdata, Date = as.Date(Date), Sum = Number*Count)
dd <- ddply(indata, .(paste(Key, City, sep=","), summarize, total=sum(Sum))
产生
1 KEY1,NEW-YORK
1 3456
在两个不同的行中,添加substr的特殊之处在于&#34; - &#34;造成两行而不是一行的问题?