Use ifelse
as in:
dat$new1 <- ifelse(dat$Q1==3, 1, 0)
More Related Contents:
- Replace a value in a data frame based on a conditional (`if`) statement
- Idiom for ifelse-style recoding for multiple categories
- Canonical tidyverse method to update some values of a vector from a look-up table
- How to plot intersecting ranges in Excel/R/Matlab [closed]
- How to create a consecutive group number
- Extract row corresponding to minimum value of a variable by group
- Remove columns from dataframe where ALL values are NA
- Merge several data.frames into one data.frame with a loop
- Overlaying histograms with ggplot2 in R
- Meaning of ~. (tilde dot) argument?
- Extract Month and Year From Date in R
- Grouped barplot in R with error bars
- Why is `vapply` safer than `sapply`?
- Why do some Unicode characters display in matrices, but not data frames in R?
- Plotting multiple time-series in ggplot
- How to hide or disable in-function printed message
- how to create two independent drill down plot using Highcharter?
- Cartesian product data frame
- Interpretation of ordered and non-ordered factors, vs. numerical predictors in model summary
- Dealing with timestamps in R
- stacked bars within grouped bar chart
- how to jitter/dodge geom_segments so they remain parallel?
- R split string by symbol
- Select rows of a matrix that meet a condition
- ggplot multiple grouping bar
- pie chart with ggplot2 with specific order and percentage annotations
- Importing a big xlsx file into R?
- How do you create vectors with specific intervals in R?
- R: apt-get install r-cran-foo vs. install.packages(“foo”)
- Round a POSIX date (POSIXct) with base R functionality