How to exclude certain observations while generating summary statistics without creating a new data


My problem is:

I have a large number of numeric variables for which I need to generate summary statistics. Some of the observations are coded "-99", which means the participant does not know the answer to the survey question.

While calculating means for such variables, I want to exclude the "-99" observations. Since I have a lot of variables, it would be quite onerous to use "subset".

Does anyone know an easier way?

PS: I know that for factors, the >- Summarize(df, exclude ="") command in the FSA package could work. I am just not sure if there is an equivalent for numeric variables.


Just make yourself a simple wrapper function around summary:

set.seed(1) x <- rnorm(100) x[sample(seq_along(x), 10)] <- -99 summary2 <- function(x) summary(x[x!=-99])

Compare results:

> summary(x) Min. 1st Qu. Median Mean 3rd Qu. Max. -99.00000 -0.70810 -0.04209 -9.79400 0.59810 2.40200 > summary2(x) Min. 1st Qu. Median Mean 3rd Qu. Max. -2.21500 -0.52640 0.07445 0.11770 0.67230 2.40200


  • Combing value of same elements
  • GraphSharp BalloonTreeLayout pins all vertices in one place
  • How to get database credentials into a c# application without committing it to source code?
  • javafx 3d performance large data set
  • Development workflow for server and client using Docker Compose?
  • Exception handling as per java coding standards
  • Accessing Windows Azure Queues from client side javascript/jquery
  • How can I include the Ivy dependency and none of its dependencies?
  • Install different versions of nuget packages inside one solution file with two projects
  • Find unique tuples in a relation represented by a BDD
  • Differences between drawing an Ellipse in Android and Java
  • JPA/EclipseLink Returning No Results
  • Whats the right place for testhelper-classes? (phpunit/best practise)
  • Calling java project from Mathematica
  • Grunt watch Running “watch” task Waiting
  • python - calculate orthographic similarity between words of a list
  • How can I determine which routines MATLAB uses to solve a sparse matrix?
  • SQL query to group by maximal sets of a column having inner consecutive distances below a threshold
  • Change device language on Android 6.0 (Android M)
  • Add Windows Feature from C#
  • How to enable large page memory for the JVM?
  • python: forcing relative imports to search from script file
  • Hide buttons on title bar in Java
  • How can we prepend rows to a react native list-view?
  • How can I get the full list of running processes on a Mac from a python app
  • vectorized indexing/slicing in numpy/scipy?
  • Spring: No transaction manager has been configured
  • msbuild create itemgroup from property group
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Spring boot 2.0.0.M4 required a bean named 'entityManagerFactory' that could not be found
  • Read text file that is not in the main package in a runnable jar
  • Roxygen error “Skipping invalid path”
  • What's the purpose of QString?
  • Calling Worksheet functions from vba in foreign language versions of Excel
  • Jackson Parser: ignore deserializing for type mismatch
  • How do I fake an specific browser client when using Java's Net library?
  • DotNetZip - Calculate final zip size before calling Save(stream)
  • Apache 2.4 - remove | delete | uninstall
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • embed rChart in Markdown