This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
Description: A set of R functions to implement the Independent RFM scoring and the RFM scoring with input breaks. | |
Author: Jack Han http://www.DataApple.net email: jackhan2008 # qq.com | |
Version: 1.3 | |
Date: 23 Dec 2013 | |
Usage: Read the article "RFM Customer Analysis with R Language" http://www.dataapple.net/?p=84 | |
################################################################################ | |
################################################################################ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# weeknum | |
eval wnum=strftime(_time, "%V") | |
# DayOfWeek | |
eval DayOfWeekC=strftime(_time, "%a") | |
# hour | |
eval hour=strftime(_time,"%H:00") | |
# date in format %y-%m-%d, eg. 13-12-17 | |
eval Date=strftime(_time, "%y-%m-%d") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function NumLeft(NumStrings As Variant, Optional Delim As String = " ") As Variant | |
Dim i As Long, numrows As Long, OutA() As Variant, j As Long, NumDig As Long, Numstring As String, StringLen As Long | |
If TypeName(NumStrings) = "Range" Then NumStrings = NumStrings.Value2 | |
If TypeName(NumStrings) = "String" Then | |
numrows = 1 | |
Else | |
numrows = UBound(NumStrings) | |
End If |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to clean names | |
standardize_name <- function(string) { | |
capped <- grep("^[^A-Z]*$", string, perl = TRUE) | |
substr(string[capped], 1, 1) <- toupper(substr(string[capped], 1, 1)) | |
# string <- gsub('_',' ',string, fixed=TRUE) | |
return(string) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# There are several domain name servers that allow | |
# for bulk searching of domain names. | |
# http://www.godaddy.com/bulk-domain-search.aspx | |
# http://www.namestation.com/bulk-domain-search | |
# However, they do not provide any wildcard support | |
# and instead expect users to supply their own list. | |
# Which is not a problem if you are an R coder. | |
# This single command will copy to the clipboard a list | |
# of mysite1 mysite2 mysite3....mysite500. You can then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load bare essentials | |
library("ggplot2") | |
library("plyr") | |
library("reshape2") | |
library("timeSeries") | |
library("TTR") | |
library("forecast") | |
# Things you might want to change |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create explicit data frames and TS objects given a list | |
market.list<- c("GR","CY","RU","RO","PL","UA","ROW") | |
for (i in market.list) { | |
tmp <- subset(data,Market==i) | |
tmp<-ts(tmp) # It's a timeseries afterall... | |
# Let's save the data somewhere so we don't get back all the time | |
filename <- paste("data_", i, sep="") | |
assign(filename, tmp) | |
save(filename, file=paste(filename, ".rda",sep="")) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dic <- data.frame(old = c("cat", "dog", "coffee", "tea", "tee"), new = c("kissa", "koira", "kahvi", "tee", "tii")) | |
sapply( unique(as.character(dic$old)) , function(i) { test.words[as.character(test.words) == i] <<- as.character(dic$new[as.character(dic$old) == i]) }) | |
test.words |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(fpp) | |
# Please make sure at least v3.10 of the forecast is loaded | |
# before running these examples. | |
# Three examples | |
beer <- aggregate(ausbeer) | |
plot(beer) | |
plot(a10) | |
plot(taylor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!TCL=4, | |
!TITLE=Qliktech Set Analysis | |
!SORT=N | |
!CHARSET=ANSI | |
!TEXT=Month To Date Last Year | |
=sum({$<CAL_YEAR={$(=max(CAL_YEAR)-1)},CAL_DATE = {"<=$(=addmonths(max(CAL_DATE),-12))"},CAL_MONTH={"=$(=max(CAL_ MONTH))"}>} SALES)) | |
! |