compare column names and make plots

和自甴很熟 提交于 2019-12-24 19:06:50

问题


I want to compare two columnnames from two data frames and create graphs with the matched columnnames from the original data frames.

a<-data.frame(a1=c(1,2,3,4,5),a2=c(2,3,4,5,6),b1=c(3,4,5,6,7),c1=c(4,5,6,7,8))
b<-data.frame(c1=c(10,20,30,40,50),b1=c(20,30,40,50,60),d1=c(30,40,50,60,70))

Output should be like: plot (b$c1,a$c1) plot (b$b1,a$b1)

I can create the plots with the above codes, but I need it to be automated because my dataframe is too large.


回答1:


Here's one way:

shared.names <- intersect(names(a), names(b))
par(mfrow=n2mfrow(length(shared.names)))
for (name in shared.names) plot(a[[name]], b[[name]], main=name)



来源:https://stackoverflow.com/questions/16530521/compare-column-names-and-make-plots

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!