I am working on a simple problem in R (but I have not yet figured it out though;p):
Given a vector vect1 <- c("Andy+Pete", "Mary + Pete", "Pete+ Amada", ..., "Amada + Steven", "Steven + Henry"). I want to create a new vector vect2 that contains all the elements in vect1 and new elements that share the following property: for every two strings "A+B" and "B+C", we concatenate it into "A+C" and add this new element into vect2. Can anyone please help me do this?
Also, I want to get all the elements standing in front of + in each string, is the following code correct?
for (i in length(vect1)){
vect3[i] <- regexpr(".*+", vect1[i])
}
3rd question: if I have a dataframe d with a Date column in the format %d-%b (for example, 01-Apr), how do I order this dataframe in an increasing order based on Date?? Let's just say d <- c(01-Apr,01-Mar,02-Jan,31-June,30-May).
vect1always two people, or can it be 1 or 3+? This sounds like combinatorial "fun".vect1into separate columns for the pairs.forloop code? @ManishSaraswat Saraswat: Yes, an example would be"Mary + Pete"&"Pete + Amada"(column 2 and 3) ="Mary + Amada". So the new vector would have the size ofvect1+ all the new concatenated elements like this.