This is a more complicated iteration of previous questions about subsetting a dataframe by a vector. So in this case I have a very large dataframe with numerous columns of crop data in it. Within that dataframe is a column entitled "STshort" which has lots of tail errors in it. I want to take remove the upper 10% and lower 10% of values from this column and have attempted it in the following manner.
First I make an object for the column "STshort" as shown below.
sh<-Maindata[,"STShort"]
Then I try to subset the data frame by the quintiles of this column in the following manner. This logic has typically worked for subsetting a vector.
Maindata<-Maindata[sh>=(quantile(sh,.10,na.rm=TRUE))&sh<=(quantile(sh,.9,na,rm=TRUE)),]
I get the following error message.
Error in quantile.default(sh, 0.1, na.rm = TRUE) : factors are not allowed
Some of my data in this column
dput(sh[1:10])
structure(c(73L, 54L, 145L, 127L, 37L, 115L, 102L, 119L, 239L,
198L), .Label = c("-10536.5041", "-1081.8875", "-11360.69846",
"-1179.834949", "-1241.222986", "-1259.302658", "-1277.333333",
"-1286.085441", "-1289.74", "-1294", "-1333.25", "-1334.138686",
"-1335.521379", "-1369.85455", "-13715.36843", "-1376.361502",
"-1380.27099", "-14.39869997", "-143.0545455", "-1516.133764",
"-156.2526551", "-1579.5", "-15917.49503", "-1683.4375", "-1699.0625",
Any ideas on how one could conceivably go about this?