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
## === 第一次用R需安裝套件 === | |
list.of.packages <- c("ggplot2", "xlsx", "FactoMineR","showtext", | |
"Cairo", "ggthemes","directlabels","dplyr") | |
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] | |
if(length(new.packages)) install.packages(new.packages) | |
# 內建圖 | |
ca_plot <- function (df,label=c("印象","品牌"),textSize=10, | |
x_limits=c(-0.5,0.6),.alpha=0.7, |
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
library(data.table) | |
library(xlsx) | |
library(dplyr) | |
library(pipeR) | |
library(car) | |
## 讀取資料 | |
fileNameA <- '3337_A卷.csv' # (手動更改參數) | |
fileNameB <- '3371_B卷.csv' # (手動更改參數) | |
# options(java.parameters = "-Xmx16g") # read.xlsx增加記憶體 |
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
## === 第一次用R需安裝套件 === | |
list.of.packages <- c("plyr", "dplyr", "sjmisc") | |
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] | |
if(length(new.packages)) install.packages(new.packages) | |
rm(list.of.packages, new.packages) | |
combine_pipe_table <- function ( | |
.data, .var_start, .var_end, .MR_num, .step) | |
{ | |
# .var_start # 表格起始變數名 |
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
# forked from hadley/recode.R | |
# https://gist.github.com/hadley/2751ba61d1c7f4eaacab | |
recode_to <- function(df, ..., match = c("first", "last")) { | |
match <- match.arg(match) | |
cases <- lapply(list(...), as.case) | |
if (identical(match, "last")) cases <- rev(cases) | |
n <- nrow(df) |
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
write.Hmisc.SPSS = function(data, datafile, codefile) { | |
## Write an SPSS file from R with variable labels from the Hmisc package | |
# source: | |
# http://stackoverflow.com/questions/10181730/information-from-label-attribute-in-r-to-variable-labels-in-spss/10261534#10261534 | |
# EXAMPLE DATA (see: http://stackoverflow.com/q/10181730/1270695) | |
# | |
# If you do not want to alter your original file, as in the example above, | |
# and if you are connected to the internet while you are using this function, | |
# you can try this self-contained function: |
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
## === 第一次用R需安裝套件 === | |
list.of.packages <- | |
c("plyr", "xlsx", "tools","dplyr","openxlsx", | |
"sampling", "magrittr", "sjmisc") | |
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])] | |
if(length(new.packages)) install.packages(new.packages) | |
rm(list.of.packages, new.packages) | |
## -- 更新 package ---- | |
if(packageDescription("openxlsx")$Version < "2.3.11") { |
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
### Using the Windows Clipboard, or Passing Data Quickly From Excel to R and Back Again | |
## http://www.r-bloggers.com/using-the-windows-clipboard-or-passing-data-quickly-from-excel-to-r-and-back-again/ | |
# Copy data out of R | |
copy.table <- function(obj, size = 4096) { | |
clip <- paste('clipboard-', size, sep = '') | |
f <- file(description = clip, open = 'w') | |
write.table(obj, f, row.names = FALSE, sep = '\t') | |
close(f) | |
} |
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
multi.freq.table = function(data, sep="+", dropzero=FALSE, clean=TRUE) { | |
## 共選分析 | |
# Takes boolean multiple-response data and tabulates it according | |
# to the possible combinations of each variable. | |
# | |
# See: http://stackoverflow.com/q/11348391/1270695 | |
counts = data.frame(table(data)) | |
N = ncol(counts) | |
counts$Combn = apply(counts[-N] == 1, 1, |
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
write.spss <- | |
function(data, datafile, codefile, varlabels=NULL) { | |
# EXAMPLE DATA (see: http://stackoverflow.com/q/10181730/1270695) | |
# | |
# If you do not want to alter your original file, as in the example above, | |
# and if you are connected to the internet while you are using this function, | |
# you can try this self-contained function: | |
# | |
# df <- data.frame(id = c(1:6), | |
# p.code = c(1, 5, 4, NA, 0, 5), |
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
combine_pipe_table <- function ( | |
.data, .var, | |
start = grep(.var, colnames(.data)), | |
Qcount, MRnum, step, key) | |
{ | |
# .var # 表格起始變數名 | |
# start # 開始欄 | |
# Qcount # piping來源題數 | |
# MRnum # 複選題數 | |
# step # piping相同題數 |
OlderNewer