[R] constant function

Eik Vettorazzi E.Vettorazzi at uke.de
Wed Mar 7 11:59:15 CET 2012

Hi Chris,
how about this:

constant<-function(x) rep(7,length(x))


Am 07.03.2012 06:41, schrieb Chris Waggoner:
> Is it possible to define a constant function (for example the zero function) in R?
> I found the following unsatisfying hack to create the "seven function":
> constant <- stepfun( x = -100:100,   y = rep(7,   201)  )
> This is mathematically unsatisfying because the domain is artificially restricted to [-100,100] rather than (-Inf,Inf).
> Additionally, unless I use pch="n" there are ugly dots on the plot (and again this feels hackish).
> Any suggestions on what else to do?
> Thanks in advance.
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Eik Vettorazzi

Department of Medical Biometry and Epidemiology
University Medical Center Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG):

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg

Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus 

More information about the R-help mailing list