> setwd("c://RQQ")<br />
> QQ=read.csv("qq.csv",header=TRUE) #read the data.<br />
> # the first question<br />
> FreqTopTen=rev(sort(table(QQ$id)))[1:10]<br />
> write.table(FreqTopTen,"FreqTop10.txt")<br />
> # the second question<br />
> QQ$time=as.Date(QQ$time) #transform the string to date<br />
> Days=unique(QQ$time) #extract the list of days<br />
> for (i in length(Days)) {<br />
+ time.i=Days[i]<br />
+ QQ.i=QQ[QQ$time==time.i,]<br />
+ ActiveTopTen<-rev(sort(table(QQ.i$id)))[1:10]<br />
+ write.table(ActiveTopTen,"ActiveTop10.txt",append=TRUE)<br />
+ }<br />
</p>
我是R新手,想了很久才写出来,还望大家指出有无错误,或者哪些可以有更优的办法。
目前的代码运行结果第一行总有一个“x”,不知是什么原因;而且有一段警告:
Warning message:
In write.table(ActiveTopTen, "ActiveTop10.txt", append = TRUE) :
appending column names to file
请大家赐教啊