# no data given, so try something like this:
# split by scanID and then check for dups
dups <- lapply(split(x$ListingPrice, x$ScanID,), function(.price){
# return sum of duplicated; non-zero => duplicated prices
sum(duplicated(.price))
})
On Thu, Nov 12, 2009 at 12:11 PM, jorgusch <hackl.schorsch at web.de>
wrote:>
> Hi,
> I have a big set of data with price lists in different periods. I want to
> check whether there are equal prices and if so, start a loop to look closer
> into it. However, my solution so far is based on a loop and I cannot think
> of a vector based approach...any ideas?
>
> # Counting vectors
> equali<-0
> noequali<-0
> resultsi<-c()
>
> #splitting the data set
> ? ?scanid<-xall$ScanID
> ? ?Uscanid<-unique(scanid)
> ? ?ULscanid<-length(Uscanid)
>
> ? ?for(q in 1:ULscanid){
> ? ? ? ?qscanid<-Uscanid[q]
> ? ? ? ?x<-subset(xall, ScanID==qscanid)
>
> ## __Testing whether there are any equal prices in this ScanID
> ? ? #-number of prices
> ? ? ? ?xLprice<-length(x$ListingPrice)
> ? ? ? ? ? ?if (xLprice > 1){
>
> ? ? ? ? #-creating list of unique prices
> ? ? ? ? ? ? ? ?xUprice<-unique(x$ListingPrice)
> ? ? ? ? ? ? ? ?xULprice<-length(xUprice)
>
> #!!!!!!!!!!!!!!!
> #- Check whether the price are all unique or not...this takes time....
>
> ? ? ? ? ? ? ? ? ? ? ?if (xULprice==xLprice){
> ? ? ? ? ? ? ? ? ? ? ? ? ?noequali<-noequali+1
> ? ? ? ? ? ? ? ? ? ? }else{
> ? ? ? ? ? ? ? ? ? ? ? ? ? ?equali<-equali+1
> ? ? ? ? ? ? ? ? ? ? }
>
>
> ? ? ? ? ?}
> ? ?}#-end ScanId
>
> Well, any ideas for a vector based solution would be a great help! It would
> help the environment for sure, otherwise my machine has to run over night
> ;-)
>
> By the way, I all the efficient guys here are somehowe environmentalists -
> no offense!
> --
> View this message in context:
http://old.nabble.com/vector-based-command-for-equal-values---if-too-slow-tp26322526p26322526.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?