A pair of my sample data is as follows, but I have more than these columns
df<-read.table(text=" ID_k2g6 ko_k2g6 jaz_k2g6 ID_k5n100 ko_k5n100 jaz_k5n100
12 60 A 15 10 A
14 40 B 15 40 A
13 100 A 65 60 B
10 20 B 35 40 B
NA NA NA 80 20 B
",header=TRUE)
Here is the intended outcome
last type class noA MjazA SDJazA noB MjazB SDJazB
6 k2 g 2 12.5 0.7 2 12 2.84
100 k5 n 2 15 0 3 40 20
As you can see, there is a pair of data. I want to get counts, mean and SD for each. last= the last digit (5 and 100), type = after the hyphen (k2 and k5) and class is after k (g and n). count, mean and SD get from ko.
I have used these codes, but it does not help me
df$id<-1:nrow(df)
setDT(df)
dat<-melt(df,id=c("id", "ko_k2g6","ko_k5n100"))
dat[,.(mean1=mean(ko_k2g6),sd1=sd(ko_k2g6),
mean2=mean(ko_k5n100),sd1=sd(ko_k5n100)),.(varaiable,value)