I'm working on the Boston Housing dataset. I filtered the observations (towns) having the lowest 'medv' and saved them after transposing to a new dataframe. I want to insert column in this new dataframe that contains the percentiles based on the original data for the feature values of these filtered observations. Here's the R code:
# load the library containing the dataset
library(MASS)
# save the data with custom name
boston = Boston
# suburb with lowest medv
low.medv = data.frame(t(boston[boston$medv == min(boston$medv),]))
low.medv
# The values I want populated in new columns:
# Finding percentile rank for crim
ecdf(boston$crim)(38.3518)
# >>> 0.9881423
ecdf(boston$crim)(67.9208)
# >>> 0.9960474
# percentile rank for lstat
ecdf(boston$lstat)(30.59)
# >>> 0.9782609
ecdf(boston$lstat)(22.98)
# >>> 0.8992095
Desired output :
Is there a way to use the ecdf function with sapply?