简体   繁体   中英

How to import data from file and plot cdf in R

I have two files with one column information. I need to plot cdf of these two column of data in one graph in R.

I used below code but I got a problem.

Error in [.data.frame (x, order(x, na.last = na.last, decreasing = decreasing)) : undefined columns selected Calls: plot -> ecdf -> sort -> sort.default -> [ -> [.data.frame

pdf(file = '$filename.pdf', width=5, height=5);
data1 <- read.csv('80211');
data2 <- read.csv('mine');

aCDFcolor <- rgb(1,0,0);
bCDFcolor <- rgb(0,1,0);

plot(ecdf(data1), col=aCDFcolor, main=NA);
plot(ecdf(data2), col=bCDFcolor, add=T);

legend('right', c('data1', 'data2'), fill=c(aCDFcolor, bCDFcolor), border=NA);

Try below, input for ecdf must be numeric.

#dummy data
set.seed(123)
data1 <- data.frame(x=rnorm(10))
data2 <- data.frame(x=rnorm(10))

aCDFcolor <- rgb(1,0,0)
bCDFcolor <- rgb(0,1,0)

#plot
plot(ecdf(data1[,1]), col=aCDFcolor, main=NA)
plot(ecdf(data2[,1]), col=bCDFcolor, add=T)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM