[英]I don't understand this message: Error in x > n : comparison of these types is not implemented
I am attempting to run a function (a z-test) over a dataframe by first defining the function and then in a seperate step apply it iteratively across all rows.我试图通过首先定义函数然后在单独的步骤中在所有行中迭代地应用它来在数据帧上运行函数(z 测试)。 The goal is to form new colunms that include the p-value of that z-test, for the given target-variables.
目标是为给定的目标变量形成包含该 z 检验的 p 值的新列。 I can't seem to get the iteration to work as I keep getting this unfamiliar error message.
我似乎无法让迭代工作,因为我不断收到这个不熟悉的错误消息。
I define the function: functionname <- function(V1,V2,V3,V4){...}
我定义了函数:
functionname <- function(V1,V2,V3,V4){...}
This step seems to work, I can input values and am getting a correct result.这一步似乎有效,我可以输入值并得到正确的结果。 My code for the iteration looks as follows:
我的迭代代码如下所示:
for (i in rownames(df)){
df[i, "newvariableA"] <- functionname(df[i,"V1"],df[i,"V2"],df[i,"V3"],df[i,"V4"])
df[i, "newvariableB"] <- functionname(df[i,"V1"],df[i,"V2"],df[i,"V3"],df[i,"V4"])
}
Which produces the erorr message产生错误消息
Error in x > n : comparison of these types is not implemented
I hope you guys could give me a pointer as to why this error is produced or to an alternative approach.我希望你们能给我一个关于为什么会产生这个错误或替代方法的指针。
Thanks!谢谢!
Edit: More info on the function output:编辑:有关函数输出的更多信息:
functionname <- function(V1,V2,V3,V4){
ges1 <- V1/sqrt(2)
ges2 <- V2/sqrt(2)
t1 <- (V3/100)*ges1
t2 <- (V4/100)*ges2
sig <- prop.test(c(t1,t2),c(ges1,ges2),correct=FALSE)$p.value
sig <- round(sig,4)
if (sig>0.05){
sig <- "ns"
} else if (sig==0){
sig <- ".0000"
} else{
sig <- substr(toString(sig),start=2,stop=100)
}
return(sig)
}
Use this用这个
for (i in 1:nrow(df)){
df[i,"newvariableA"] <- ztestd(df[i,"V1"],df[i,"V2"],df[i,"V3"],df[i,"V4"])
}
This was a problem that I saw long ago when I got a class of R few years back and there wasn't any solution to this at that time.这是我很久以前在学习 R 课程时看到的一个问题,当时没有任何解决方案。 so we used DF as a tibble rather than as a dataframe then problem was gone I didn't get it how that fixed the problem but it did if you don't have any constraints to use df as a dataframe you can try it and use as tibble
所以我们使用 DF 作为 tibble 而不是作为数据框然后问题就消失了作为小标题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.