[英]Bytea data format in R shiny
這是我需要從PostgreSQL數據庫提取的數據的示例表。 樣本數據
如您所見,iv_file(它是一個十六進制數字)列為Bytea格式。 因此,當我嘗試在R中提取onlu的iv_file列時,得到以下內容。
`iv_file
1 \\x
2 \\x
3 \\x
4 \\x
5 \\x
6 \\x364630353037303036463035303830303646303530443030364530353142303036453035333730303643303535463030364230353838303036393035414530303638303544313030363630354634303036353035313630313634303533373031363330353537303136323035373730313630303539373031354630354236303135453035443630313544303546363031354330353136303235423035333430323539303535343032353930353733303235373035393130323536303542313032353530354430303235343035463030323533303530453033353230353245303335303035344430333446303536423033344530353842303334443035414130333443303543383033344130354538303334413035303830343438303532373034343730353435303434363035363530343434303538343034343430354132303434333035433230343431303545313034343030353031303533463035314630
數據與原始數據不同。 (請注意,原始數據也有很長的數字)那么如何在R中使用bytea數據格式? 或如何轉換?
我不相信你可以轉換它。 Bytea數據基本上是叮咬數據。 我建議不要將其拉入rdata框架。 Bytea通常是位數據,它是圖像或不能以傳統格式存儲的內容。
另一種方法是使用JDBC,它通常負責轉換。 我將看一下require(RPostgreSQL)以了解如何完成它。
將其加載到R中后,您也許可以將其轉換回去。嘗試類似的方法
udecode <- function(string){
uconv <- function(chars) intToUtf8(strtoi(chars, 16L))
ufilter <- function(string) {
if (substr(string, 1, 1)=="|") uconv(substr(string, 2, 5)) else string
}
string <- gsub("\\\\u([[:xdigit:]]{4})", ",|\\1,", string, perl=TRUE)
strings <- unlist(strsplit(string, ","))
string <- paste(sapply(strings, ufilter), collapse='')
return(string)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.