X[X < .1] <- 0
(or NA, although 0 sounds more appropriate in this case.)
Matrices are just vectors with dimensions, so you can treat them like a vector when you assign to them. In this case, you’re creating a boolean vector over X that indicates the small values, and it assigns the right-hand-side to each element that’s TRUE.
Related Contents:
- Replace specific characters within strings
- How to replace NA values in a table for selected columns
- Replace NA in column with value in adjacent column
- Replace all particular values in a data frame
- Match values in data frame with values in another data frame and replace former with a corresponding pattern from the other data frame
- Remove all text before colon
- How to replace NaN value with zero in a huge data frame?
- Replace given value in vector
- R: Replace multiple values in multiple columns of dataframes with NA
- Replace values in a vector based on another vector
- Replace a value NA with the value from another column in R
- Replacing occurrences of a number in multiple columns of data frame with another value in R
- Replace in a factor column
- Replace empty values with value from other column in a dataframe
- How to convert Excel date format to proper date in R
- Multirow axis labels with nested grouping variables
- How do I arrange a variable list of plots using grid.arrange?
- Select the first and last row by group in a data frame
- Horizontal/Vertical Line in plotly
- Dummy variables from a string variable
- Proper/fastest way to reshape a data.table
- What are the main differences between R data files?
- readRDS(file) in R
- How do you order the fill-colours within ggplot2 geom_bar
- ggplot2 0.9.0 automatically dropping unused factor levels from plot legend?
- How do I change the formatting of numbers on an axis with ggplot? [duplicate]
- Code to import data from a Stack overflow query into R
- Changing whisker definition in geom_boxplot
- Non-equi join using data.table: column missing from the output
- How to add different lines for facets
- Using lists inside data.table columns
- Changing facet label to math formula in ggplot2
- backtransform `scale()` for plotting
- Remove all of x axis labels in ggplot [duplicate]
- ggmap Error: GeomRasterAnn was built with an incompatible version of ggproto
- Merge or combine by rownames
- General suggestions for debugging in R
- Plot over multiple pages
- ggplot, drawing multiple lines across facets
- Add secondary X axis labels to ggplot with one X axis
- How to convert time (mm:ss) to decimal form in R
- R ifelse statement
- Split a string by any number of spaces
- Changing Million/Billion abbreviations into actual numbers? ie. 5.12M -> 5,120,000 [duplicate]
- Using ifelse in R
- Library is not writable
- How to facet a plot_ly() chart?
- Call a function from c++ via environment Rcpp
- Selecting only unique values from a comma separated string [duplicate]
- Passing a variable name to a function in R