开发者

R: using previously determined variable as part of png file name

I am still new to R and I have searched around for a solution to my simpl开发者_StackOverflow社区e question, but I haven't found an answer that I've been able to get to work. I am looking to use a previously identified variable per data set, here variable=SNPname to include in script for automated generation of graph output in png format.

I am using this to generate a kmeans plot and have:

(cl <- kmeans(FilteredData[,6:7], 5, nstart=25))
png("C:/temp/$SNPnamegraph1.png")                 #SNPname to include in filename
plot(FilteredData[,6:7], col=cl$cluster)
points(cl$centers, col=1:5, pch=8)
dev.off()

where I want to include that variable in line 2 at the beginning of the file name. Is there a simple way to do this that I am just missing?


Close, you're just missing the use of paste() and setwd()

setwd("C:/temp/") # use this to set where you want things saved
...
c1 <- kmeans...
png(paste(SNPname, " graph1.png", sep=""))
...

If it's in a loop of some kind, you might need to use SNPname[loop_var]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜