[R] substitute values in a vector,dataframe
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Thu May 31 10:46:29 CEST 2001
On Thu, 31 May 2001, Frank Gerrit Zoellner wrote:
> Hi!
>
> I've got a dataframe with -Inf values inside and i want to substitute
them with 0. The dataframe is only one column. How can I do this in R?
df[df[, 1] %in% -Inf, 1] <- 0
as in
df <- data.frame(a=c(1:3, -Inf, 4))
df[df[, 1] %in% -Inf, 1] <- 0
df
a
1 1
2 2
3 3
4 0
5 4
If there were more than one column, use lapply.
--
Brian D. Ripley, ripley at stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list