![](/img/trans.png)
[英]Split Character String at Underscore Using scan() Function in R - strsplit() vs. scan() Comparison
[英]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.