簡體   English   中英

R字符串拆分函數中的非字符參數(strsplit)

[英]Non character argument in R string split function (strsplit)

這有效

x <- "0.466:1.187:2.216:1.196"
y <- as.numeric(unlist(strsplit(x, ":")))

blat$LRwAvg值看起來都像上面的X但這不起作用

for (i in 1:50){
  y <- as.numeric(unlist(strsplit(blat$LRwAvg[i], "\\:")))
  blat$meanLRwAvg[i]=mean(y)
}

因為:

strsplit(blat$LRwAvg[i], "\\:") 中的錯誤:非字符參數

如果我有一個、兩個或空反斜杠並不重要。

我的問題是什么? (不是一般的,我的意思是在這個特殊任務中,技術上)

由於 agstudy 暗示blat$LRwAvg <- as.character(blat$LRwAvg)在循環修復之前

blat$meanLRwAvg <- blat$gtFrqAvg #or some other variable in data frame with equal length
blat$LRwAvg <- as.character(blat$LRwAvg)
for (i in 1:50){
  y <- as.numeric(unlist(strsplit(blat$LRwAvg[i], "\\:")))
  blat$meanLRwAvg[i]=mean(y)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM