Skip to content

Instantly share code, notes, and snippets.

View sithjaisong's full-sized avatar

Sith Jaisong sithjaisong

View GitHub Profile
@sithjaisong
sithjaisong / stakfile
Last active August 29, 2015 14:10
Stacking files
# Set the Directory
setwd("~/yourpath")
# Geting a List of Files
files <- listfiles(pattern= \\.text$')
# บางครั้ง อาจจะเจอกับ
info = file.info(files)
@sithjaisong
sithjaisong / mutiggplot
Last active August 29, 2015 14:20
loop for multiple ggplot and arrange them in the rows and columns you wish for
###########################Header##############################################
# title : multiggplot.R;
# purpose : create muti histogram of all varibles in the dataset;
# producer : prepared by S. Jaisong ([email protected]);
# last update : in Los Baños, Laguna, PHL, April 2015;
# inputs : "airquality" data from R;
# outputs : exaple.pdf;
# remarks 1 : ;
# remarks 2 : ;
###############################End#############################################
@sithjaisong
sithjaisong / normality test with Shapiro-Wilk test fro all vars
Created September 8, 2015 09:06
this script for test the normality for all vars
lapply(data, shapiro.test)
$DH
Shapiro-Wilk normality test
data: X[[i]]
W = 0.4481, p-value < 2.2e-16
@sithjaisong
sithjaisong / order_row_by_trt.R
Last active October 16, 2016 08:33
reorder row follwoing name of variable
dat <- read_csv("/Users/sithjaisong/Desktop/ycom.csv") # โหลดไฟล์ที่ต้องการ
# ตอนนี้ข้อมูลที่ผมมีนั้น จะเห็นว่า trt ที่เรียงนั้น มันถูกเรียงตาม rep
head(dat)
Source: local data frame [6 x 15]
trt rep sm sm y moi hill panicle sunk mc_sunk float_sunk mc_float tgw sunk mc_tgw_sunk tgw float mc_tgw_float
(chr) (int) (int) (dbl) (dbl) (int) (int) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl) (dbl)
1 PR 1 1 2.320 14.0 108 214 261.8 13.1 64.1 14.0 24.548 12.80 3.425 14.0
2 PR 1 2 2.570 15.6 108 230 283.8 13.7 62.1 14.5 23.958 12.20 3.524 14.2
@sithjaisong
sithjaisong / plot.CRD.layout.R
Last active October 16, 2016 08:16
plot.CRD.layout function: the function for generate completely radomized design
library(agricolae)
library(desplot)
plot.CRD.layout <- function(trt_name, num_rep){
repeticion <- rep(num_rep, length(trt))
CRD <- design.crd(trt, r = repeticion, serie = 0)
CRD_layout <- CRD$book
@sithjaisong
sithjaisong / plot.RCBD.layout.R
Created October 16, 2016 08:32
plot.RCBD.layout is the function used to generate layout of randomized complete block design of experiment
library(desplot)
library(agricolae)
library(RColorBrewer)
plot.RCBD.layout <- function(trt_name, num_block){
repeticion <- rep(num_block, length(trt_name))
RCBD <- design.rcbd(trt_name, r = repeticion, serie = 0)
#title: code sample for ploting polynomial model
# load packages
library(readxl) # load readxl package
library(ggplot2) # load ggplot2 paackage
library(dplyr) # load dplyr package
library(polynom) # load polynom
library(gsheet) # load gsheet
# load data
@sithjaisong
sithjaisong / start_up.R
Created January 14, 2017 15:22
You newly install R program when all of your packages are lost.
# List of useful packages
pkg <- c("tidyr", "dplyr", "ggplot2", "knitr", "rmarkdown")
# Check if packages are not installed and assign the
# names of the uninstalled packages to the variable new.pkg
new.pkg <- pkg[!(pkg %in% installed.packages())]
# If there are any packages in the list that aren't installed,
# install them
if (length(new.pkg)) {
@sithjaisong
sithjaisong / pairwise.wilcox.test.R
Created March 26, 2017 03:52
Perform pairwise Wilcoxon test, classify groups by significance and plot results
# ref:https://fabiomarroni.wordpress.com/2017/03/25/perform-pairwise-wilcoxon-test-classify-groups-by-significance-and-plot-results/
library(multcompView)
first.set<-cbind(rnorm(100,mean=1.8),1)
second.set<-cbind(rnorm(100,mean=0.9),2)
third.set<-cbind(rnorm(100,mean=1),3)
full<-rbind(first.set,second.set,third.set)
pp<-pairwise.wilcox.test(full[,1], full[,2], p.adjust.method = "none", paired = FALSE)
@sithjaisong
sithjaisong / utmtolatlong.R
Last active March 31, 2017 01:55
script to transform utm data to lat-long data
# ref:https://sites.google.com/a/lakeheadu.ca/yong-luo/blog/convert-utm-to-longlat-in-r
library(rgdal)
# prepare UTM coordinates matrix
utmcoor<-SpatialPoints(cbind(utmdata$X,utmdata$Y), proj4string=CRS("+proj=utm +zone=30")) # UTM zone Central Thailand: 47P
#utmdata$X and utmdata$Y are corresponding to UTM Easting and Northing, respectively.
#zone= UTM zone
# converting
longlatcoor<-spTransform(utmcoor,CRS("+proj=longlat"))