I'm trying to write an R function that will produce a string for later output. The data comes in a dataframe with one column and rownames.
fcc <- structure(list(temp = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 1L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 1L, 3L, 3L, 4L, 4L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L
), .Label = c("H", "M", "N", "S"), class = "factor")),
.Names = "temp", row.names =
c(NA, 135L), class = c("tbl_df", "tbl", "data.frame"))
outStr <- "name"
for(i in 1:nrow(fcc)){
if (fcc[i,] != "N"){
outStr <- paste0(outStr," ", rownames(fcc)[i],"(",fcc[i,],")")
}
}
Instead of the characters "H","M", etc. that I expect R returns 1,2,etc.
When I type in fcc[i] at the command prompt I can see the character I need:
> fcc[1,]
Source: local data frame [1 x 1]
temp
1 N
I am pretty sure this is me misunderstanding factors, but I can't figure it out.
Thanks! Matt