I want to find the nth smallest number for every column in a data.frame.
In the below example I specify actually the second smallest value using the dcast nth function. Can someone help with the coding of the function?
library(vegclust)
library(dplyr)
data(wetland)
dfnorm = decostand(wetland,"normalize")
dfchord = dist(dfnorm, method = "euclidean")
dfchord = data.frame(as.matrix(dfchord)
number_function = function(x) nth(x,2) # can change 2 to any number..
answer_vector = apply(dfchord, 2, number) # here, 2 specifying apply on columns
The actual answer would be something like this..
ans = c(0.5689322,0.579568297,0.315017693,0.315017693,0.632246369, 0.868563003, 0.704638684, 0.35827587, 0.725220337, 0.516397779) # length of 1:38