-
Notifications
You must be signed in to change notification settings - Fork 0
/
sampling.R
26 lines (17 loc) · 974 Bytes
/
sampling.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
library(xlsx)
data_transactions<-read.csv("/Users/tyrusyuen/Library/CloudStorage/OneDrive-TheChineseUniversityofHongKong/2022 H2/UoT Datathon/UoT Datathon 2022 Shared Drive/transactions.csv")
data_demographics<-read.csv("/Users/tyrusyuen/Library/CloudStorage/OneDrive-TheChineseUniversityofHongKong/2022 H2/UoT Datathon/UoT Datathon 2022 Shared Drive/demographics.csv")
merge<-merge(x = data_transactions, y = data_demographics, by = "household_key", all.x = TRUE)
merge1<-subset(merge,BRAND == 'National')
dim(data_transactions)
dim(merge)
merge_noNA<-merge1[rowSums(is.na(merge1['INCOME_DESC'])) == 0, ]
wb = createWorkbook()
for (i in 1:20) {
set.seed(sample(1:1e9, 1))
index <- sample(1:nrow(merge_noNA), 35e3)
index
sample<-merge_noNA[index, ]
writeDataTable(wb, sheet=addWorksheet(wb, paste("Sample",i)),sample, startCol=1)
}
saveWorkbook(wb, "/Users/tyrusyuen/Library/CloudStorage/OneDrive-TheChineseUniversityofHongKong/2022 H2/UoT Datathon/filename.xlsx")