Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require(RPostgreSQL)
- drv = dbDriver("PostgreSQL")
- con = dbConnect(drv, host = ..., post =..., dbname =..., user=..., password=...)
- df = dbGetQuery(con, query_string)
- dbDisconnect(con)
- df = data.frame(id = c(1:100), arrcol = c(rep(paste0("{{",paste0(1:99,collapse=","),"}}"),10)))
- df$arrcol = gsub(fixed=T, "{", "", df$arrcol)
- df$arrcol = gsub(fixed=T, "}", "", df$arrcol)
- # Attempt 1:
- df$arrcol = as.numeric(df$arrcol)
- # Error: (list) object cannot be coerced to type 'double'
- # Attempt 2:
- df$arrcol = lapply(df$arrcol, function(x) strsplit(x, ",", fixed=T))
- # no error, but now the data appears to be stored as a list of character lists:
- # arrcol[1]: list(c("1", "2", "3", "4", "5",...
- # Attempt 3:
- df$arrcol = lapply(df$arrcol, function(x) as.numeric(unlist(strsplit(x, ",", fixed=T))))
- # this one seems to work
- df$arrcol = lapply(df$arrcol, function(x) as.numeric(unlist(strsplit(x, ",", fixed=T))))
- newdf = read.table(text = df$arrcol, header = F, sep = ",")
- df = cbind(df, newdf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement