Try this:
x <- structure(list(day = 19, C1 = structure(1L, .Label = c("", "C1"
), class = "factor"), C2 = structure(2L, .Label = c("", "C2"), class =
"factor"),
C3 = structure(1L, .Label = c("", "C3"), class = "factor"),
Q1 = structure(2L, .Label = c("", "Q1"), class = "factor"),
Q2 = structure(2L, .Label = c("", "Q2"), class = "factor"),
Q3 = structure(1L, .Label = c("", "Q3"), class = "factor")), .Names =
c("day",
"C1", "C2", "C3", "Q1", "Q2", "Q3"), row.names = "8", class =
"data.frame")
paste(x[1, 1], do.call(paste, c(x[1, x != ""][, -1], list(sep="_"))),
sep=" -")
# Output looks like this
paste(x[1, 1], do.call(paste, c(x[1, x != ""][, -1], list(sep="_"))),
sep=" -")
x[1, 2] <- "C1"
paste(x[1, 1], do.call(paste, c(x[1, x != ""][, -1], list(sep="_"))),
sep=" -")
[1] "19 -C1_C2_Q1_Q2"
HTH,
Garrett
On Fri, Mar 2, 2012 at 2:39 PM, chuck.01 <CharlieTheBrown77@> wrote:
I have this type of format:
structure(list(day = 19, C1 = structure(1L, .Label = c("", "C1"
), class = "factor"), C2 = structure(2L, .Label = c("", "C2"), class =
"factor"),
? ?C3 = structure(1L, .Label = c("", "C3"), class = "factor"),
? ?Q1 = structure(2L, .Label = c("", "Q1"), class = "factor"),
? ?Q2 = structure(2L, .Label = c("", "Q2"), class = "factor"),
? ?Q3 = structure(1L, .Label = c("", "Q3"), class = "factor")), .Names =
c("day",
"C1", "C2", "C3", "Q1", "Q2", "Q3"), row.names = "8", class =
"data.frame")