【问题标题】:Using R - Converting vector from a table to another table使用 R - 将向量从一个表转换为另一个表
【发布时间】:2012-08-13 21:12:03
【问题描述】:

我正在对图形进行一些批处理,但在从字符串中定位另一个表时遇到了问题。

# Source table

t<-read.csv(file="Results.csv",header=TRUE)

# Graph Input

g<-read.csv(file="Graphs.csv",header=TRUE)

图表输入有一个我想要生成的所有图表的列表,源表中包含所有数据:

y<-paste(g[1,1])
x<-paste(g[1,2])

x 的向量是t$massyt$luminosity 其中massluminosity 的数据在表t 中。但是,如果我输入y,我只会得到向量或表达式"t$luminosity",而不是包含数据值的表。

如何让它调用正确的信息?

【问题讨论】:

    标签: r vector input expression


    【解决方案1】:

    我建议使用 ggplot2 中的 aes_string 函数的解决方法:

    library(stringr)
    library(ggplot2)
    x <- str_replace(x, "t[$]", "")
    y <- str_replace(y, "t[$]", "")
    ggplot(data=t) + geom_point(aes_string(x=x, y=y)
    

    【讨论】:

    • 嗯,好的,感谢您这么快的回复。那么它不可能与使用绘图功能一起工作吗?我试过改变 x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多