Stacks Image 20108

For Academics

Replace values in a data frame

It is often necessary to replace values in a column in data.frame, for example NAs with 0s.

The following code will replace NA values with 0, in variable x:

x[ is.na(x) ] <- 0

Similarly, one can deal with inf values:

x[ is.infinite(x) ] <- 0

This page provided the original spark.

Make sure that replacing inf with zero does not bias your analysis.

To selectively change unwanted values from data:

newdata<-olddata
newdata[newdata<0.25]<-NA # example, make small values in the oldata column NA
Previous Post 35 / 50 Post

Tag:

Sex chromosome papers RSS


The genome sequence of the Scarce Copper, Lycaena virgaureae (Linnaeus, 1758) (Lepidoptera: Lycaenidae)
Link

The genome sequence of the Violet Copper, Helleia helle (Denis & Schiffermüller), 1776 (Lepidoptera: Lycaenidae)
Link

Neo-X-Linked Chromosome Polymorphism: Cytogenetic Insights from Passalites nemorivagus (Mammalia, Cervidae)
Link