save plots in for loop
0
0
Entering edit mode
6.9 years ago
mbk0asis ▴ 680

Hi.

I'm trying to read a list of strings and 'grep' them one by one from a data frame and draw and save the plots using R 'for loop' function. However, I got warning message and nor plots.

"Warning message:
In grep(cpg, colnames(dta)) :
  argument 'pattern' has length > 1 and only the first element will be used"

Here's the code I used,

for (cpg in cpg.list){
      dta1 <- dta[,grep(cpg,colnames(dta))]
      jpeg(paste(files[cpg]), '.jpg', width = 700, height = 500)
      par(mar=c(3,3,3,3))
      stripchart(dta1, method='jitter', vertical=T)
      boxplot(dta1, add = T)
      dev.off()
}

Can someone explain what I did wrong?

Thank you!

R for loop jpeg grep • 2.1k views
ADD COMMENT
7
Entering edit mode

Try to print out the content of the cpg variable, it's probably not what you think it is.

Based on the error message it's a vector (while you expect it to be a simple character string if I'm not mistaken).

ADD REPLY
0
Entering edit mode

please provide output for

head(dta)

and

colnames(dta)

and contents of

cpg.list
ADD REPLY

Login before adding your answer.

Traffic: 2579 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6