Skip to content

Instantly share code, notes, and snippets.

@nilforooshan
nilforooshan / rescale.exe
Last active March 30, 2019 09:46
f90: Re-scale a vector to a desired mean and variance *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / smpl_prob.exe
Last active March 30, 2019 09:45
f90: Define the type of sampling. Give the set and sample sizes and find the number of possibilities and the probability for each possibility *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / srt_mrg.exe
Last active March 30, 2019 09:45
f90: Sort and merge two numeric files by their first column *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / symetric.exe
Last active March 30, 2019 09:41
f90: Lazy to check whether your matrix is symetric or not! Try this program. The program will tell you where the matrix is asymetric. *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / trace.exe
Last active March 30, 2019 09:41
f90: Calculate the trace of a matrix *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / traceped.exe
Last active March 30, 2019 09:40
f90: Trace a numerical pedigree (either paternal or maternal) to the base generation *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / ztest.exe
Last active March 30, 2019 09:40
f90: Insert a random variable (x) from a normal distribution with mean (mu) and standard deviation (std) and get the zscore and Prob(Z =< zscore) (i.e. the area under the curve). *.exe and *.out are the Windows and Linux executables.
@nilforooshan
nilforooshan / tri2full.md
Last active September 26, 2024 23:39
R: Convert an upper.tri or a lower.tri data.frame to a full matrix

Convert an upper.tri or a lower.tri data.frame to a full matrix

The function:

tri.2full = function(df) # df is a data.frame with 3 columns
{
   dimmat = (sqrt(1+8*nrow(mydf))-1)/2 # Assuming 0 rows are not skipped.
   mat = matrix(, nrow=dimmat, ncol=dimmat)
 mat[upper.tri(mat, diag=TRUE)] = df[,3]
@nilforooshan
nilforooshan / renum_seq.md
Last active March 30, 2019 09:13
R: Renumber an array sequentially from 1:n

Renumber an array sequentially from 1:n

as.integer(as.factor(c(11,9,13,14,14,14)))

[1] 2 1 3 4 4 4

as.integer(as.factor(c("b","a","c","d","d","d")))
@nilforooshan
nilforooshan / drop_1st_last_string.md
Last active October 2, 2024 22:08
R: Drop the first or the last element(s) from text strings

Drop the first or the last element(s) from text strings

txtstr = c("abcd", "efgh")
substr(txtstr, 1, nchar(txtstr)-1)

[1] "abc" "efg"