I'm currently working on a set of genetic data with two groups. P[Anynumber], P[Anynumber].PE
These groups are patients in different stages (P=Initial, PE = More than 24 weeks) Right now I have a larger group of P than PE. Around 96 samples of P, 65 of PE in the same dataframe
I already create a function to plot a PCA with both stages, but this over-representation caused by P group move all the PCA.
For that reason, what I would like to do is remove those that are not duplicates. I mean, I just want a dataframe that contain both samples. For example: P2 and PE_2, P3 and PE_3, and remove those who have P[AnyNumber] but not PE
Example dataframe:
data <- data.frame(matrix(rbinom(10*1000, 1, .5), ncol=10))
colnames(data) <- c("P1","P1.PE","P10","P100","P101","P101.PE", "P102", "P102.PE","P103","P104")
What I expect it would be a dataframe with the columns:
P1 | P1.PE | P101 | P101.PE | P102 | P102.PE |
What I tried to do is filter the dataframe using grepl firstly and strsplit, but I got and error and probably there's an easier way to do it.
data.filter <- data[,c(unlist(data.frame(strsplit(colnames(data[,grepl("\\.",colnames(data))]),"\\."),stringsAsFactors = F)[1,]),colnames(data[,grepl("\\.",colnames(data))]))]
Thank you in advance.