[英]Non character argument in R string split function (strsplit)
This works这有效
x <- "0.466:1.187:2.216:1.196"
y <- as.numeric(unlist(strsplit(x, ":")))
Values of blat$LRwAvg
all look like X
above but this doesn't work blat$LRwAvg
值看起来都像上面的X
但这不起作用
for (i in 1:50){
y <- as.numeric(unlist(strsplit(blat$LRwAvg[i], "\\:")))
blat$meanLRwAvg[i]=mean(y)
}
Because of:因为:
Error in strsplit(blat$LRwAvg[i], "\\:") : non-character argument
strsplit(blat$LRwAvg[i], "\\:") 中的错误:非字符参数
It doesn't matter if I have one, two or null backslashes.如果我有一个、两个或空反斜杠并不重要。
What's my problem?我的问题是什么? (Not generally, I mean in this special task, technically)
(不是一般的,我的意思是在这个特殊任务中,技术上)
As agstudy implied blat$LRwAvg <- as.character(blat$LRwAvg)
before loop fixed it由于 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.