Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在dplyr top\n中使用字符串作为变量名_R_Dplyr - Fatal编程技术网

在dplyr top\n中使用字符串作为变量名

在dplyr top\n中使用字符串作为变量名,r,dplyr,R,Dplyr,我试图使用字符串变量将列名传递到top\n中,但没有得到结果 metric <- "column_name" top_n(df, 5, metric) 这也不起作用您需要使用sym()(或在base中使用as.name())将字符串转换为符号,然后添加将其取消引用 top_n(df, 5, !!sym(metric)) 如果您共享输入以及所需的输出,将会有所帮助。什么是度量标准?表示整数的字符串,例如'5'?表示列名的字符串,例如'column1'? top_n(df, 5, !!sy

我试图使用字符串变量将列名传递到
top\n
中,但没有得到结果

metric <- "column_name"
top_n(df, 5, metric)
这也不起作用

您需要使用
sym()
(或在base中使用
as.name()
)将字符串转换为符号,然后添加
将其取消引用

top_n(df, 5, !!sym(metric))

如果您共享输入以及所需的输出,将会有所帮助。什么是度量标准?表示整数的字符串,例如
'5'
?表示列名的字符串,例如
'column1'
top_n(df, 5, !!sym(metric))