Hello,
And another way, with which(., arr.ind = TRUE).
In two steps, to make it clearer.
i <- which(df[grep("var[123]", names(df))] == "a", arr.ind = TRUE)
df[i] <- "z"
df
# var1 var2 var3 var4 var5
#1zAz1 light
#2bBb4 light
#3cCc9 heavy
#4
Hello List,
I use the following code to generate a donut plot.
# Compute percentages
eth$fraction = eth$individuals / sum(eth$individuals)
# Compute the cumulative percentages (top of each rectangle)
eth$ymax = cumsum(eth$fraction)
# Compute the bottom of each rectangle
eth$ymin = c(0, head(eth$yma
Hi,
something like this (a customised version based on this:
https://stackoverflow.com/questions/25768305/r-replace-multiple-values-in-multiple-columns-of-dataframes-with-na
):
--- snip ---
col_idx<-grep("^var[123]", names(df))
m1<-as.matrix(df[,col_idx])
m1[m1=="a"]<-"z"
df[col_idx]<-m1
df
--
Hi Luigi,
I would take a slightly different approach. Maybe this is helpful.
idV <- grep("var[123]",colnames(df))
df[,idV][df[,idV]=="a"] <- "z"
df
var1 var2 var3 var4 var5
1zAz1 light
2bBb4 light
3cCc9 heavy
4zDz 16 heavy
5b
Helo
I have a dataframe whose names are similar and I would like to change
the rows containing given values simultaneously.
I can select the columns using library(dplyr) but I can't modify the data:
```
library(dplyr)
> df <- data.frame(var1 = c(letters[1:3], letters[1:4]),
+ var2 =
5 matches
Mail list logo