Recoding in R

https://dplyr.tidyverse.org/reference/recode.html

# For character values, recode values with named arguments only. Unmatched # values are unchanged. char_vec <- sample(c("a", "b", "c"), 10, replace = TRUE) recode(char_vec, a = "Apple")
#> [1] "Apple" "b" "Apple" "b" "c" "Apple" "c" "c" "b" #> [10] "Apple"
recode(char_vec, a = "Apple", b = "Banana")
#> [1] "Apple" "Banana" "Apple" "Banana" "c" "Apple" "c" "c" #> [9] "Banana" "Apple"

 

My example:

court2qe$abc2<-recode(
court2qe$abc,"this is" = "X",
"That is" = "Y")

R purrr

library(tidyverse)

my_list<-list(
c(1,2,6),
c(4,7,1),
c(9,1,5)
)

my_list[[1]] %>% mean()
my_list %>% map_dbl(mean)
map(my_list,mean)
my_list %>% map(~ . *1)
my_list %>% map(~ . *2)

pop<-rnorm(10000)
n<-1:1000
m1<-rep(NA,length(n))

for (i in n){
x<-sample(pop,i)
m1[i]<-mean(x)
}
plot(m1,type="l")