Re: [R] for loop question in R

2021-12-22 Thread Kai Yang via R-help
Hi Rui and Ivan,Thank you explain of the code for me in detail. This is very helpful. And the code works well now.Happy Holiday,Kai On Wednesday, December 22, 2021, 02:30:49 PM PST, Rui Barradas wrote: Hello, y[i] and c[i] are character strings, they are not variables of data set mpg.

Re: [R] for loop question in R

2021-12-22 Thread Rui Barradas
Hello, There's a stupid typo in my previous post. Inline Às 22:30 de 22/12/21, Rui Barradas escreveu: Hello, y[i] and c[i] are character strings, they are not variables of data set mpg. To get the variables, use, well, help("get"). Note that I have changed the temp dir to mine. So I created

Re: [R] for loop question in R

2021-12-22 Thread Rui Barradas
Hello, y[i] and c[i] are character strings, they are not variables of data set mpg. To get the variables, use, well, help("get"). Note that I have changed the temp dir to mine. So I created a variable to hold the value tmpdir <- "c:/temp/" for (i in seq(nrow(mac))){ mpg %>% filter(hwy

Re: [R] for loop question in R

2021-12-22 Thread Kai Yang via R-help
strange, I got error message when I run again: Error: unexpected symbol in: "    geom_point()   ggsave" > } Error: unexpected '}' in "}" On Wednesday, December 22, 2021, 10:18:56 AM PST, Kai Yang wrote: Hello Eric, Jim and Ivan, Many thanks all of your help. I'm a new one in R area. I

Re: [R] for loop question in R

2021-12-22 Thread Kai Yang via R-help
Hello Eric, Jim and Ivan, Many thanks all of your help. I'm a new one in R area. I may not fully understand the idea from you.  I modified my code below, I can get the plots out with correct file name, but plots  are not using correct fields' name. it use y[i], and c[i] as variables' name, does

Re: [R] for loop question in R

2021-12-22 Thread Ivan Krylov
On Wed, 22 Dec 2021 16:58:18 + (UTC) Kai Yang via R-help wrote: > mpg %>%    filter(hwy <35) %>%     ggplot(aes(x = displ, y = y[i], > color = c[i])) +     geom_point() Your code relies on R's auto-printing, where each line of code executed at the top level (not in loops or functions) is run

Re: [R] for loop question in R

2021-12-22 Thread jim holtman
You may have to add an explicit 'print' to ggplot library(ggplot2) library(tidyverse) y <- c("hwy","cty") c <- c("cyl","class") f <- c("hwy_cyl","cty_class") mac <- data.frame(y,c,f) for (i in nrow(mac)){ mpg %>%filter(hwy <35) %>% print(ggplot(aes(x = displ, y = y[i], color = c[i])) +

Re: [R] for loop question in R

2021-12-22 Thread Eric Berger
Try replacing "c:/temp/f[i].jpg" with paste0("c:/temp/",f[i],".jpg") On Wed, Dec 22, 2021 at 7:08 PM Kai Yang via R-help wrote: > Hello R team,I want to use for loop to generate multiple plots with 3 > parameter, (y is for y axis, c is for color and f is for file name in > output). I created a

Re: [R] for loop question in R

2021-12-22 Thread Andrew Simmons
nrow() is just the numbers of rows in your data frame, use seq_len(nrow()) or seq(nrow()) to loop through all row numbers On Wed, Dec 22, 2021, 12:08 Kai Yang via R-help wrote: > Hello R team,I want to use for loop to generate multiple plots with 3 > parameter, (y is for y axis, c is for color a

Re: [R] For loop question

2012-11-10 Thread David Winsemius
On Nov 10, 2012, at 10:17 PM, dae wrote: > Thanks. That got me the answer. Good. That's what the FAQ is for. You should also read the Posting Guide where the reasons behind the request to include context for replies is laid out. > This works: > > symbols = c("IEF","SPY") > > getSymbols(sym

Re: [R] For loop question

2012-11-10 Thread dae
Thanks. That got me the answer. This works: symbols = c("IEF","SPY") getSymbols(symbols) for(symbol in symbols) { assign(symbol, to.monthly(get(symbol), indexAt="endof")) } #end -- View this message in context: http://r.789695.n4.nabble.com/For-loop-question-tp4649215p46492

Re: [R] For loop question

2012-11-10 Thread David Winsemius
On Nov 10, 2012, at 2:36 PM, dae wrote: > I have this code: > IEF <- to.monthly(IEF, indexAt="endof") > SPY <- to.monthly(SPY, indexAt="endof") > > I would like to use a for loop instead of separate entries, > so the only code that needs to be modified is the list > of symbols. > > symbols <- c

Re: [R] for loop question Documentation and its application for calculating euclidean distance on MDS ordination axis scores

2008-10-01 Thread Ben Bolker
> I will post data probably tonight, but here is my problem. I have > preformed an MDS on a set of data. I have the scores of the four axes > that > are the optimal solution. I want to calculate the euclidean distance > between time steps of the ordination. See ?dist for a much faster sol

Re: [R] for loop question Documentation and its application for calculating euclidean distance on MDS ordination axis scores

2008-10-01 Thread Gábor Csárdi
Actually, help.search("for") finds Control(base) Control Flow which is exactly where 'for' is documented. In general, if you want the manual page of reserved words, then you'll have to quote them: ?"for" Gabor On Wed, Oct 1, 2008 at 3:39 PM, stephen sefick <[EMAIL PROTECTED]> wrote:

Re: [R] for loop question Documentation and its application for calculating euclidean distance on MDS ordination axis scores

2008-10-01 Thread Gabor Grothendieck
One must write ?"for" presumably since for is a reserved word in R. On Wed, Oct 1, 2008 at 9:39 AM, stephen sefick <[EMAIL PROTECTED]> wrote: > ?for doesn't return anything help.search("for") doesn't return anything- > Is the for loop so prevelant in computer programing that the > documentation is