0

I have a set of data, with it's own metadata. I get some of the columns to list all the data from the given set of data.

Then I use this loops to store it in a matrix (I tried a data.frame and a list, but didn't work either). The entries are strings.

#############
ii_c <- metadades$item_id[metadades$tipus_item == "comentari"]
g_c <- metadades$grup[metadades$tipus_item == "comentari"]
i_c <- metadades$item[metadades$tipus_item == "comentari"]

in_c <- data_ent[, ii_c]

c_l <- list()

for(i in 1:ncol(in_c)){
  c_l[[i]] <- in_c[,i][!is.na(in_c[,i])]
}

j <- 0
l <- 0

c_cl <- matrix(ncol=3)

for(i in 1:ncol(in_c)){
  if(mode(c_l[[i]])=="numeric"){
    j=j+1
  } else {
    for(k in 1:length(c_l[i])){
      c_cl[i-j+l,] = c(g_c[i],i_c[i],c_l[i][k])
      l=l+1
    }
  }
}

df_cl <- as.data.frame(c_cl)
#############

This way afterwards I would be able to plot it. Nevertheless I've tried to list (instead of making a matrix) all the dataframes and later on I could be able to cbind them (but it gave me errors aswell).

The next step would be to do a tableGrob and a grid.draw, to print it in a report.

Vash
  • 1
  • 1
  • Please provide us with a [minimum example](http://stackoverflow.com/help/mcve). See the following link for help in producing a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – lmo May 11 '16 at 14:07

1 Answers1

0

Got the solution from my workmate,,

df_comentaris <- data.frame(grup=NA, item=NA, comentari =NA)

for (i in metadades$item_id[metadades$tipus_item=='comentari']) {

  comentaris <- dades[!is.na(dades[i]),i]
  grup <- metadades$grup[metadades$item_id == i]
  item <- metadades$item[metadades$item_id == i]
  df_aux <- data.frame(grup=rep(grup,length(comentaris)), item=rep(item,length(comentaris)), comentari=comentaris)
  df_comentaris <- rbind(df_comentaris, df_aux)

}

df_comentaris <- df_comentaris[2:nrow(df_comentaris),]
Vash
  • 1
  • 1