Try this
df <- data.frame(V1=c(1,2,4), V2=c("a","a","b"), V3=c(2,3,1))
df[df$V2 == "b", c("V1", "V3")] <- df[df$V2 == "b", c("V3", "V1")]
which yields:
> df
V1 V2 V3
1 1 a 2
2 2 a 3
3 1 b 4
More Related Contents:
- Repeat each row of data.frame the number of times specified in a column
- Filter data.frame rows by a logical condition
- Split column at delimiter in data frame [duplicate]
- Pass a data.frame column name to a function
- How to convert a list consisting of vector of different lengths to a usable data frame in R?
- Select groups based on number of unique / distinct values
- Assign multiple columns using := in data.table, by group
- Filtering a data frame on a vector [duplicate]
- Remove an entire column from a data.frame in R
- Split dataframe into multiple output files
- How do I delete rows in a data frame?
- Convert data.frame column to a vector?
- Add new row to dataframe, at specific row-index, not appended?
- How to use a string variable to select a data frame column using $ notation [duplicate]
- Growing a data.frame in a memory-efficient manner
- R list of lists to data.frame
- Splitting a data.frame by a variable [duplicate]
- Check whether values in one data frame column exist in a second data frame
- Unlist a data frame by rows, not columns
- Deleting columns from a data.frame where NA is more than 15% of the column length [duplicate]
- Using lapply to apply a function over list of data frames and saving output to files with different names
- DT[!(x == .)] and DT[x != .] treat NA in x inconsistently
- Return df with a columns values that occur more than once [duplicate]
- Row-wise sum of values grouped by columns with same name
- Replicate each row of data.frame and specify the number of replications for each row?
- Undefined columns selected when subsetting data frame
- Difference between `names(df[1])
- How to create a new variable in a data.frame based on a condition?
- Data.frame Merge and Selection of values which are common in 2 Data.frames
- Interpolating timeseries