1

I am new to R. I meet a very strange issue. I read my data from MongoDB into R. The last column is incorrectly readed as structure.

Initially, it looks fine when I just view it. Image 1

When I use dput(head(meter_char)):

structure(list(
x_NMI = c(90141L, 90165L, 90157L, 90085L, 90148L, 90093L), 
Building = c("double story", "unit", "Double story house", "Double story house", "Double story house", "Double story house"), 
`number of people` = c("5", "2", "3", "2", "6", "4"), 
pool = c("no", "no", "No", "No", "No", "No"), 
`type of AC` = c("Evap", "Evap", "Reverse cycle", "None", "Evaporative, Reverse cycle", "Reverse cycle"), 
No = structure(list(` of AC` = c("1", "1", "", "None", "Three", "Three")), row.names = c(NA, 6L), class = "data.frame")), row.names = c(NA, 
6L), class = "data.frame")

The last column (expected to be "No of AC") is corrupted. It should not be structure(list(.

I think this is caused by "." in the cloume name. Is there a way to change the content of the last colume to just c("1", "1", "", "None", "Three", "Three"))?

Thanks!

chen
  • 69
  • 1
  • 6
  • `colnames(meter_char) <- c("a","b",...)` with a vector of column names. Or for just one, `colnames(meter_char)[6] <- "no_of_ac"`. – r2evans Oct 21 '19 at 22:12
  • Related: https://stackoverflow.com/q/58494640 – r2evans Oct 21 '19 at 22:12
  • The problem is not just the column name. Is about the content...It incorrectly becomes a structure.. – chen Oct 21 '19 at 22:15
  • It's a `list`, not a `structure` ... the fact that it shows `structure(` there is the same reason that it shows `structure(` at the very top of the output. Your query is returning a "list-column" which, in this case, is a `data.frame`. So your query is returning a `data.frame` as a column. This suggests that it's not a simple table that you are querying. If you want to fix it, just to `meter_char[[6]] <- meter_char[[6]][[1]]` or such. (You may still want to rename it.) – r2evans Oct 21 '19 at 22:18

0 Answers0