Extract two different vectors from set in R

How can I extract the set of (a) and set of (b) as shown in the image to two different vectors, the first vector for (a) values and the second for (b) values >Solution : Using names > tmp=c("a"=1,"b"=2,"a"=3,"b"=5) > tmp[names(tmp)=="a"] a a 1 3

Wide to Long preserving a group

How would I transform the following data.frame from wide to long while also generating a group column? Example data: dat <- data.frame(ID=paste0("id",1:10),readout1_g1=rnorm(10),readout1_g2=rnorm(10),readout1_g3=rnorm(10),readout2_g1=rnorm(10),readout2_g2=rnorm(10),readout2_g3=rnorm(10)) I have the following groups I am interested in that are part of the column names groups <- c("g1","g2","g3","g1","g2","g3") dat ID readout1_g1 readout1_g2 readout1_g3 readout2_g1 readout2_g2 readout2_g3 1 id1 0.2732715 -0.6328317 -1.3024276 1.7248944… Read More Wide to Long preserving a group

How to change class character to class date in R without getting NA results

I’ve got a data table with a column of dates: ex_dates <- c("2022-01-01", "2022-05-28") they are now at class character, how can I change them to class date? I’ve tried this code: data$date <- as.Date(data$date,"%d/%m/%Y") but it changes the whole column to NA. >Solution : You can use lubridate package with the function YMD: class(data$date)… Read More How to change class character to class date in R without getting NA results

Vectorised argument for a function in R. The function gives out multiple data frames, whereas I'd like it to output only one

I’d like to compute trimmed mean for each trimming proportion alpha, and then see which trimming proportion gives the minimal variance of the trimmed means, when Bootstrap simulations of size N=200 are applied. The problem that I have, is that when I try to create a data frame of column1 = mean and column2 =… Read More Vectorised argument for a function in R. The function gives out multiple data frames, whereas I'd like it to output only one