gpt4 book ai didi

string - 将字符串转换为 aes_string 的美学

转载 作者:行者123 更新时间:2023-12-01 14:45:22 24 4
gpt4 key购买 nike

<分区>

我有以下问题。

我想转一个字符串,例如

> a<-paste('x=col1,y=col2,fill=col3')

转换为 aes_string 接受的形式:x='col1',y='col2',fill='col3'

这是函数的一部分:

>fun<-function(data,aes.string=''){
aes_mapping <- aes_string(aes.string)
p <- ggplot(df.data,mapping=aes_mapping )
p <- p + geom_point()
return(p)
}

如果我打电话

> fun(df.sam,a)
> Error in parse(text = x) : <text>:1:7: unexpected ','
1: x=col1,
^

>dput(df.sam)
structure(list(col1 = c(1.99340197320543, 4.96225966782141, 1.42191486886353,
5.41389048265218, 1.48427007201488, 3.43977166739915, 2.43656907238302,
2.863856404804, 2.71825401870433, 3.17825292487285), col2 = c(76.2306398916608,
5.89150952248784, 38.634046526178, 28.3032368687166, 14.7025137552809,
9.11163890447616, 46.3416263715291, 31.9935691220763, 49.799629992835,
24.5153013442625), col3 = c(152, 600, 305, 375, 305, 300, 229,
330, 229, 300)), .Names = c("col1", "col2", "col3"), row.names = c(NA,
10L), class = "data.frame")

感谢任何帮助!

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com