Re: [R] Looping

2024-02-20 Thread Steven Yen
Steven from iPhone > On Feb 19, 2024, at 4:56 PM, Steven Yen wrote: > > Thanks to all. Glad there are many options. > > Steven from iPhone > >>> On Feb 19, 2024, at 1:55 PM, Rui Barradas wrote: >>> >> Às 03:27 de 19/02/2024, Steven Yen escreveu: >>> I need to read csv files repeatedly,

Re: [R] Looping

2024-02-19 Thread Marc Girondot via R-help
In my package HelpersMG, I have included a function to read in one time all the files of a folder and they are stored in a list: read_folder(   folder = try(file.choose(), silent = TRUE),   file = NULL,   wildcard = "*.*",   read = read.delim,   ... ) In your case, for example:

Re: [R] Looping

2024-02-18 Thread Rui Barradas
Às 03:27 de 19/02/2024, Steven Yen escreveu: I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, 24 altogether. That is, data<-read.csv(“data1.csv”) … data<-read.csv(“data24.csv”) … Is there a way to do this in a loop? Thank you. Steven from iPhone

Re: [R] Looping

2024-02-18 Thread Richard O'Keefe
f <- function (filename) { data<- read.csv(filename) .. } for (filename in paste0("data", 1:24, ".csv")) f(filename) Depending on what exactly you have in your file system, for (filename in system("ls data*.csv", TRUE)) f(filename) might work. On Mon, 19 Feb 2024 at 16:33, Steven Yen

Re: [R] Looping

2024-02-18 Thread avi.e.gross
8, 2024 10:28 PM To: R-help Mailing List Subject: [R] Looping I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, 24 altogether. That is, data<-read.csv(“data1.csv”) … data<-read.csv(“data24.csv”) … Is there a way to do this in a loop? Thank you. St

Re: [R] Looping

2024-02-18 Thread Peter Langfelder
Try for (ind in 1:24) { data = read.csv(paste0("data", ind, ".csv")) ... } Peter On Mon, Feb 19, 2024 at 11:33 AM Steven Yen wrote: > > I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, > 24 altogether. That is, > > data<-read.csv(“data1.csv”) > … >

[R] Looping

2024-02-18 Thread Steven Yen
I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, 24 altogether. That is, data<-read.csv(“data1.csv”) … data<-read.csv(“data24.csv”) … Is there a way to do this in a loop? Thank you. Steven from iPhone [[alternative HTML version deleted]]

Re: [R] Looping through all matrix columns each 1 row at a time

2022-04-21 Thread Eric Berger
Hi Paul, I am not sure I understand your question, but perhaps the following is helpful. In particular, the apply() function used with MAR=1, applies a function to a matrix row-wise. set.seed(123) m <- matrix(sample(1:6,5*12,replace=TRUE),ncol=12) ## dummy data m [,1] [,2] [,3] [,4] [,5]

[R] Looping through all matrix columns each 1 row at a time

2022-04-20 Thread Paul Bernal
Dear R friends, One question, so, thanks to the Bert's kind feedback, I was able to create my matrix using the following code: dice_rolls = 120 num_dice = 1 dice_sides = 6 #performing simulation dice_simul = data.frame(dice(rolls = dice_rolls, ndice = num_dice, sides = dice_sides, plot.it =

Re: [R] Looping through data error

2021-04-13 Thread Bert Gunter
Well, if I understand your query, wouldn't the following simple approach suffice -- it assumes that the results for each company are ordered by year, as your example seems to show: ## test is your example data ## first remove NA's test2 <- na.omit(test) ## Now just use tapply(): > out

Re: [R] Looping through data error

2021-04-13 Thread e-mail ma015k3113 via R-help
Rui, excellent diagnosis and suggestion. It worked but my damn logic is still not delivering what I want-will spend more time on it tomorrow. Kind regards Ahson > On 13 April 2021 at 17:06 Rui Barradas wrote: > > > Hello, > > A close parenthesis is missing in the nd if. > > > for (i in

Re: [R] Looping through data error

2021-04-13 Thread e-mail ma015k3113 via R-help
Jim, thanks for taking the time to look into this. Yes, these if else statements are so confusing. I tried your amended scode and it does not work. The error are as follows: Error: unexpected '}' in " }" > NUMBER_OF_SHARES[i] = 100 / is.na(CLOSE_SHARE_PRICE[i]) > } Error: unexpected '}' in "

Re: [R] Looping through data error

2021-04-13 Thread Rui Barradas
Hello, Typo, inline. Às 17:06 de 13/04/21, Rui Barradas escreveu: Hello, A close parenthesis is missing in the nd if. Should be "the 2nd if". Rui Barradas for (i in 1:(nrow(PLC_Return)-1)){   if (i == 1){     NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i])   } else

Re: [R] Looping through data error

2021-04-13 Thread Rui Barradas
Hello, A close parenthesis is missing in the nd if. for (i in 1:(nrow(PLC_Return)-1)){ if (i == 1){ NUMBER_OF_SHARES[i] = 100/is.na(CLOSE_SHARE_PRICE[i]) } else if(is.na(PLC_Return[i, 1]) == is.na(PLC_Return[i + 1, 1])){ NUMBER_OF_SHARES[i]=0 } else { NUMBER_OF_SHARES[i] =

Re: [R] Looping through data error

2021-04-13 Thread jim holtman
Your code was formatted incorrectly. There is always a problem with the 'else' statement after an 'if' since in R there is no semicolon to mark the end of a line. Here might be a better format for your code. I would recommend the liberal use of "{}"s when using 'if/else' i <- 0 for (i in

[R] Looping through data error

2021-04-13 Thread e-mail ma015k3113 via R-help
Dear All,I have a dataframe with 4 variables and I am trying to calculate how many shares can be purchased with £100 in the first year when the company was listed The data looks like: COMPANY_NUMBER YEAR_END_DATE CLOSE_SHARE_PRICE NUMBER_OF_SHARES 22705

Re: [R] Looping thorugh dataframe

2020-07-22 Thread William Dunlap via R-help
> library(dplyr, warn.conflicts=FALSE) > d <- data.frame(Company=c("MATH","IFUL","SSI","MATH","MATH","SSI"), > Turnover=c(2,3,5,7,9,11)) > d %>% group_by(Company) %>% summarize(Count=n(), MeanTurnover=mean(Turnover), > TotalTurnover=sum(Turnover)) `summarise()` ungrouping output (override with

Re: [R] Looping thorugh dataframe

2020-07-22 Thread Sarah Goslee
Hi, Your sample code suggests that you don't yet understand how R works, and might benefit from a tutorial or two. However, your verbal description of what you want is quite straightforward. Here's a R-style way to count the number of times each company appears, and to get the mean value of

Re: [R] Looping thorugh dataframe

2020-07-22 Thread e-mail ma015k3113 via R-help
Bert, thanks for responding to my email. I do realise that newbie's like my can expect curt answers but not to worry. I am definitely learning 'R' and what I posted are also statements from R. The statements run perfectly well but don't do what I want them to do. My mistake I have posted sample

Re: [R] Looping through a dataframe

2020-07-21 Thread Jim Lemon
Hi Ahson, Guessing what your data frame might look like, here are two easy ways: All_companies<-data.frame(year=c(1970:2015,2000:2015,2010:2015), COMPANY_NUMBER=c(rep(1,46),rep(2,16),rep(3,6)), COMPANY_NAME=c(rep("IBM",46),rep("AMAZON",16),rep("SPACE-X",6))) # easy ways

Re: [R] Looping through a dataframe

2020-07-21 Thread Roger Bos
What you are asking is one area where the package data.table really shines. You didn't provide an example, but based on your question you would do something like: library(data.table) dt <- as.data.table(All_companies) dt[, .N, by=COMPANY_NAME] You will have to read up on data.table, but .N

Re: [R] Looping through a dataframe

2020-07-21 Thread John Kane
It occurs to me a simple table command will do what you say you want but I suspect the real analysis is more complicated dat1 <- data.frame(aa = sample(letters[1:5], 10, replace = TRUE), bb = 1:10) table(dat1$aa) On Tue, 21 Jul 2020 at 14:01, John Kane wrote: > As Bert says

Re: [R] Looping through a dataframe

2020-07-21 Thread John Kane
As Bert says that does not look like R Have a look an these links for some suggestions on asking questions here. http://adv-r.had.co.nz/Reproducibility.html http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example On Tue, 21 Jul 2020 at 13:42, Bert Gunter wrote:

Re: [R] Looping through a dataframe

2020-07-21 Thread Bert Gunter
What language are you programming in? -- it certainly isn't R. I suggest that you stop what you're doing and go through an R tutorial or two before proceeding. This list cannot serve as a substitute for doing such homework (is this homework, btw? -- that's off topic here) nor can we provide such

[R] Looping through a dataframe

2020-07-21 Thread e-mail ma015k3113 via R-help
Dear All, I have a dataframe which has a few thousand companies with unique company numbers and names and each company has data for several years and each year is stored in a separate row. I want to get a total for the number of years of data for each company. When I loop through the data

Re: [R] Looping with looping

2019-04-19 Thread ani jaya
Thank you very much, Dr. Snow, your suggestion helps a lot. Best, Saat On Fri, Apr 19, 2019 at 4:14 AM Greg Snow <538...@gmail.com> wrote: > When the goal of looping is to compute something and save each > iteration into a vector or list, then it is usually easier to use the >

Re: [R] Looping with looping

2019-04-18 Thread Greg Snow
When the goal of looping is to compute something and save each iteration into a vector or list, then it is usually easier to use the lapply/sapply/replicate functions and save the result into a single list rather than a bunch of global variables. Here is a quick example that does the same

[R] Looping with looping

2019-04-18 Thread ani jaya
Dear R community, I'm trying to create a looping to see the effect of number of samples from one dataset. Lets say I have 10 values in a single data frame and I want to see the mean of each sampling let say from 2-9 number of sampling. But I want to do the repetition let say up to 100 for each

Re: [R] looping using 'diverse' package measures

2017-10-19 Thread David L Carlson
tment of Anthropology Texas A University College Station, TX 77843-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Li Jiang Sent: Thursday, October 19, 2017 4:08 AM To: r-help@r-project.org Subject: [R] looping using 'diverse' package measures Hi every

Re: [R] looping using 'diverse' package measures

2017-10-19 Thread Michael Dewey
Dear Li Not absolutely sure what you want to do but try ?aggregate ?by ?apply (or one of the other apply functions, possibly tapply On 19/10/2017 11:29, Li Jiang wrote: Hi everyone, I'm new at R (although I'm a Stata user for some time and somehow proficient in it) and I'm trying to use the

[R] looping using 'diverse' package measures

2017-10-19 Thread Li Jiang
Hi everyone, I'm new at R (although I'm a Stata user for some time and somehow proficient in it) and I'm trying to use the 'diverse' R package to compute a few diversity measures on a sample of firms for a period of about 10 years. I was wondering if you can give me some hints on how to best

[R] looping using 'diverse' package measures

2017-10-19 Thread Li Jiang
Hi everyone, I'm new at R (although I'm a Stata user for some time and somehow proficient in it) and I'm trying to use the 'diverse' R package to compute a few diversity measures on a sample of firms for a period of about 10 years. I was wondering if you can give me some hints on how to best

Re: [R] Looping Through QuantMod Objects

2017-08-02 Thread Joshua Ulrich
Use auto.assign = FALSE in your getFinancials() call, and use viewFinancials() to extract the data you want. items <- c("Cash & Equivalents", "Short Term Investments", "Cash and Short Term Investments") tickers <- c("AAPL", "IBM", "MSFT") for (ticker in tickers) { Data <-

[R] Looping Through QuantMod Objects

2017-08-02 Thread Sparks, John James
Dear R Helpers, I have run into a problem trying to perform a number of actions on a set of quantmod data objects through a loop and I am hoping that this is an easy problem for someone else as opposed to very difficult for me. The example task is to get the first three objects of the quarterly

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread David L Carlson
Date, format: "1985-10-01" "1985-11-01" ... Would be preferable. - David L Carlson Department of Anthropology Texas A University College Station, TX 77840-4352 From: Paul Bernal [mailto:paulberna...@gmail.com] Sent: Tuesday, March 28, 2017 9

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
> > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul > Bernal > Sent: Tuesday, March 28, 2017 9:12 AM > To: Ng Bo Lin <ngboli...@gmail.com> > Cc: r-help@r-project.org > Subject: Re: [R] Looping Through DataFrames with D

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ng Bo Lin
Hi Paul, Using the example provided by Ulrik, where > exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01”, > "1986-01-01"), Transits = c(NA, NA, NA, NA)) > exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = > c(15,20)), You could also try the following

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ng Bo Lin
Hi Paul, The date format that you have supplied to R isn’t exactly right. Instead of supplying the format “%Y-%m-%d”, it appears that the format of your data adheres to the “%e-%B-%y” format. In this case, %e refers to Day, and takes an integer between (0 - 31), %B refers to the 3 letter

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread David L Carlson
77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal Sent: Tuesday, March 28, 2017 9:12 AM To: Ng Bo Lin <ngboli...@gmail.com> Cc: r-help@r-project.org Subject: Re: [R] Looping Through DataFrames with Differing Lenghts Dear f

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear Bo Lin, I tried doing Containerdata$TransitDate<-as.Date(Containerdata$TransitDate, "%e-%B-%y") but I keep getting NAs. I also tried a solution that I saw in stackoverflow doing: > lct<-Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C") [1] "C" > > Sys.setlocale("LC_TIME", lct) [1]

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friends Ng Bo Lin, Mark and Ulrik, thank you all for your kind and valuable replies, I am trying to reformat a date as follows: Data<-read.csv("Container.csv") DataFrame<-data.frame(Data) DataFrame$TransitDate<-as.Date(DataFrame$TransitDate, "%Y-%m-%d") #trying to put it in -MM-DD

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Ulrik Stervbo
Hi Paul, does this do what you want? exdf1 <- data.frame(Date = c("1985-10-01", "1985-11-01", "1985-12-01", "1986-01-01"), Transits = c(NA, NA, NA, NA)) exdf2 <- data.frame(Date = c("1985-10-01", "1986-01-01"), Transits = c(15, 20)) tmpdf <- subset(exdf1, !Date %in% exdf2$Date) rbind(exdf2,

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-28 Thread Paul Bernal
Dear friend Mark, Great suggestion! Thank you for replying. I have two dataframes, dataframe1 and dataframe2. dataframe1 has two columns, one with the dates in -MM-DD format and the other colum with number of transits (all of which were set to NA values). dataframe1 starts in 1985-10-01

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Anthoni, Peter (IMK)
Hi Paul, match might help, but without a real data sample, it is hard to check if the following might work. mm=match(df.col378[,"Date"],df.col362[,"Date"]) #mm will have NAs, where there is no matching date in df.col362 #and have the index of the match, where the two dates match

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Ulrik Stervbo
You could use merge() or %in%. Best, Ulrik Mark Sharp schrieb am Mo., 27. März 2017, 22:20: > Make some small dataframes of just a few rows that illustrate the problem > structure. Make a third that has the result you want. You will get an > answer very quickly. Without a

Re: [R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Mark Sharp
Make some small dataframes of just a few rows that illustrate the problem structure. Make a third that has the result you want. You will get an answer very quickly. Without a self-contained reproducible problem, results vary. Mark R. Mark Sharp, Ph.D. msh...@txbiomed.org > On Mar 27, 2017,

[R] Looping Through DataFrames with Differing Lenghts

2017-03-27 Thread Paul Bernal
Dear friends, I have one dataframe which contains 378 observations, and another one, containing 362 observations. Both dataframes have two columns, one date column and another one with the number of transits. I wanted to come up with a code so that I could fill in the dates that are missing in

Re: [R] looping problem

2017-02-02 Thread greg holly
ginal Message- > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of greg > holly > > Sent: Thursday, February 2, 2017 4:13 PM > > To: Rui Barradas <ruipbarra...@sapo.pt> > > Cc: r-help mailing list <r-help@r-project.org> > > Subject: Re: [R

Re: [R] looping problem

2017-02-02 Thread PIKAL Petr
p mailing list <r-help@r-project.org> > Subject: Re: [R] looping problem > > Thanks so much for this. Unfortunately, cbind did not work. Basically, I like > to > put an extra column named "chr" in the combined file from 22 chr. > So chr colum will be "1" for the

Re: [R] looping problem

2017-02-02 Thread greg holly
Thanks so much for this. Unfortunately, cbind did not work. Basically, I like to put an extra column named "chr" in the combined file from 22 chr. So chr colum will be "1" for the portion of chr1 in the combined file, 2 for the portion of chr2 in the combined file and so on. Regards, Greg On

Re: [R] looping problem

2017-02-02 Thread Rui Barradas
Hello, If I understand correctly, just use ?cbind. Rui Barradas Em 02-02-2017 13:33, greg holly escreveu: Hi Rui; Is there any way to insert the chr ids in numeric as 1,2..,22 in the final output. Here is output from str(temp). So I need also chr ids in a column. 1 rs58108140

Re: [R] looping problem

2017-02-02 Thread greg holly
Hi Rui; Is there any way to insert the chr ids in numeric as 1,2..,22 in the final output. Here is output from str(temp). So I need also chr ids in a column. 1 rs58108140 10583 G A -0.070438 0.059903 2 rs189107123 10611 C G -0.044916 0.085853 Regards, Greg On Wed, Feb 1,

Re: [R] looping problem

2017-02-01 Thread greg holly
Hi Rui; I do appreciate for this. Thanks so much. I will try ASAP. Regards, Greg On Wed, Feb 1, 2017 at 1:32 PM, Rui Barradas wrote: > Hello, > > If what you want is to combine the files into one data.frame then there > are 2 things you should see: > > 1) You create a

Re: [R] looping problem

2017-02-01 Thread Rui Barradas
Hello, If what you want is to combine the files into one data.frame then there are 2 things you should see: 1) You create a variable named 'temp' and don't ever use it. 2) You never combine the data.frames you read in. Try instead the following. temp <- data.frame() for(i in 1:22) {

[R] looping problem

2017-02-01 Thread greg holly
Hi all; I have 22 directories named chr1, chr2,,chr22. Each directory has a file named "Z-score.imputed". I would like to combine Z-score.imputed files into one. I wrote the following loop but did not get any results. Your helps are highly appreciated. regards, Greg temp<-c() for(i in

Re: [R] Looping through data tables (or data frames) by removing previous individuals

2016-10-03 Thread Charles C. Berry
On Mon, 3 Oct 2016, Frank S. wrote: Dear R users, [deleted] I want to get a list of "k" data tables (or data frames) so that each contains those individuals who for the first time are at least 65, looping on each of the dates of vector "v". Let's consider the following example with 5

Re: [R] Looping through data tables (or data frames) by removing previous individuals

2016-10-03 Thread Ista Zahn
Hi Frank, How about library(lubridate) dtf <- merge(dt, expand.grid(id = dt$id, refdate = v), by = "id") dtf[, gt65 := as.period(interval(fborn, refdate), unit = "years") > years(65)] dtf <- dtf[gt65 == TRUE,][, .SD[refdate == min(refdate)], by = id] Best, Ista On Mon, Oct 3, 2016 at 1:17 PM,

Re: [R] Looping through different groups of variables in models

2016-09-01 Thread Kai Mx
Thanks so much everybody, especially to Dennis. I didn't really occur to me that I could put the models into a list. I have used dplyr for simple data transformations and will definitely look into it. On Thu, Sep 1, 2016 at 8:10 AM, Dennis Murphy wrote: > Hi: > > See inline.

Re: [R] Looping through different groups of variables in models

2016-08-31 Thread Jim Lemon
Hi Kai, Perhaps something like this: kmdf<-data.frame(group=rep(c("exp","cont"),each=50), time=factor(rep(1:5,20)), condition=rep(rep(c("hot","cold"),each=25),2), value=sample(100:200,100)) for(timeindx in levels(kmdf$time)) { for(condindx in levels(kmdf$condition)) {

Re: [R] Looping through different groups of variables in models

2016-08-31 Thread Bert Gunter
Kai: 1. I think that this is a very bad idea, statistically, if I understand you correctly. Generally, your model should incorporate all groups, time points, and conditions together, not individually. 2. But plotting results in "small multiples" -- aka "trellis plots" may be useful. This is done

[R] Looping through different groups of variables in models

2016-08-31 Thread Kai Mx
Hi all, I am having trouble wrapping my head around a probably simple issue: After using the reshape package, I have a melted dataframe with the columns group (factor), time (int), condition (factor), value(int). These are experimental data. The data were obtained from different treatment

Re: [R] looping through rows of a logical matrix for combination with and testing of a numeric vector

2015-12-03 Thread debra ragland via R-help
Or sorry, I should clarify, I struggle with putting components together when it comes to looping. On Thursday, December 3, 2015 11:43 AM, debra ragland wrote: Thanks again! And no Bert, this is not homework. I have a very minimal background in R and struggle with

Re: [R] looping through rows of a logical matrix for combination with and testing of a numeric vector

2015-12-03 Thread debra ragland via R-help
Thanks again! And no Bert, this is not homework. I have a very minimal background in R and struggle with putting concepts together. But thanks anyway. On Thursday, December 3, 2015 11:04 AM, Boris Steipe wrote: Use your logical vector to extract the x, y values

Re: [R] looping through rows of a logical matrix for combination with and testing of a numeric vector

2015-12-03 Thread Boris Steipe
Use your logical vector to extract the x, y values for the test from the rows of the matrix: x <- mat[3, x2] y <- mat[3, !x2] Or: use the formula version of wilcox.test as explained in ?wilcox.test B. On Dec 3, 2015, at 10:28 AM, debra ragland via R-help wrote: >

[R] looping through rows of a logical matrix for combination with and testing of a numeric vector

2015-12-03 Thread debra ragland via R-help
I have read in a sequence alignment and have done the necessary steps to separate and store the elements of the original input into a new list of character vectors. I have compared the sequence list to a "standard" vector, such that the return is a matrix of logical values indicating TRUE if

Re: [R] looping through rows of a logical matrix for combination with and testing of a numeric vector

2015-12-03 Thread Bert Gunter
I should have added -- is this homework? There is a no homework policy on this list. Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Thu, Dec 3, 2015 at 7:54 AM, Bert Gunter wrote: >

[R] Looping through multiple sub elements of a list to compare to multiple components of a vector

2015-12-02 Thread debra ragland via R-help
I think I am making this problem harder than it has to be and so I keep getting stuck on what might be a trivial problem.  I have used the seqinr package to load a protein sequence alignment containing 15 protein sequences;     > library(seqinr)    > x =

Re: [R] Looping through multiple sub elements of a list to compare to multiple components of a vector

2015-12-02 Thread Adams, Jean
First, a couple posting tips. It's helpful to provide some example data people can work with. Also, please post in plain text (not html). If you have a single standard for comparison, you might find an approach like this helpful. # example data mylist <- c("AAEBCC", "AABDCC", "AABBCD") list.2

Re: [R] Looping help

2015-07-31 Thread PIKAL Petr
-project.org] On Behalf Of April Smith Sent: Friday, July 31, 2015 2:21 AM To: r-help@r-project.org Subject: [R] Looping help I have never looped before and know I need to. I am unsure how to proceed: - Action I need done: d(Data[1,2:399], q=0, boot=TRUE, boot.arg=list(num.iter=1000

Re: [R] Looping help

2015-07-31 Thread Jim Lemon
] to the return values } } Jim From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of April Smith Sent: Friday, July 31, 2015 2:21 AM To: r-help@r-project.org Subject: [R] Looping help I have never looped before and know I need to. I am unsure how to proceed: - Action I need done: d

[R] Looping help

2015-07-30 Thread April Smith
I have never looped before and know I need to. I am unsure how to proceed: - Action I need done: d(Data[1,2:399], q=0, boot=TRUE, boot.arg=list(num.iter=1000)) - I need this to happen to all rows, I need All[1,2:399] to increase to All[2:399], etc. - But I also need the results

[R] Looping Through List of .csv Files to Work with Subsets of the Data

2015-06-08 Thread Chad Danyluck
Hello, I want to subset specific rows of data from 80 .csv files and write those subsets into new .csv files. The data I want to subset starts on a different row for each original .csv file. I've created variables that identify which row the subset should start and end on, but I want to loop

Re: [R] Looping Through List of .csv Files to Work with Subsets of the Data

2015-06-08 Thread Chad Danyluck
Thank you Don. I've incorporated your suggestions which have helped me to understand how loops work better than previously. However, the loop gets stuck trying to read the current file: mig.processed.data - read.csv(/Users/cdanyluck/Documents/Studies/MIG - Dissertation/Data

Re: [R] Looping Through List of .csv Files to Work with Subsets of the Data

2015-06-08 Thread William Dunlap
participant.files - list.files(/Users/cdanyluck/Documents/Studies/MIG - Dissertation/Data Syntax/MIG_RAW DATA TXT Files/Plain Text Files) Try adding the argument full.names=TRUE to that call to list.files(). Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jun 8, 2015 at 7:15 PM, Chad

Re: [R] Looping Through List of .csv Files to Work with Subsets of the Data

2015-06-08 Thread MacQueen, Don
So you have 80 files, one for each participant? It appears that from each of the 80 files you want to extract three subsets of rows, one set for baseline one set for audio one set for free What I think I would do, if the above is correct, is create one master file. This file will have

[R] Looping and break

2015-03-02 Thread Scott Colwell
Hello, I apologies for bringing up next and break in loops given that there is so much on the net about it, but I've tried numerous examples found using Google and just can't seem to get this to work. This is a simple version of what I am doing with matrices but it shows the issue. I need to

Re: [R] Looping and break

2015-03-02 Thread Rolf Turner
On 03/03/15 15:04, Jeff Newmiller wrote: Your example is decidedly not expressed in R, though it looks like you tried. Can you provide the hand-computed result that you are trying to obtain? Note that the reason you cannot find anything about next or break in R is that they don't exist. Point

Re: [R] Looping and break

2015-03-02 Thread Jeff Newmiller
Sigh. To be positive is to be wrong at the top of one's lungs. Next I will be told R has a goto statement. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.us

Re: [R] Looping and break

2015-03-02 Thread Jeff Newmiller
Your example is decidedly not expressed in R, though it looks like you tried. Can you provide the hand-computed result that you are trying to obtain? Note that the reason you cannot find anything about next or break in R is that they don't exist. There are generally alternative ways to

Re: [R] Looping and break

2015-03-02 Thread Rolf Turner
On 03/03/15 16:08, Jeff Newmiller wrote: Sigh. To be positive is to be wrong at the top of one's lungs. Next I will be told R has a goto statement. I am ***positive*** that it hasn't! :-) Well, 99.999% confident. Although I guess it's not inconceivable that some misguided nerd might

[R] looping multipanel plots to different figures

2015-02-19 Thread efisio solazzo
Dear, cannot find a way to direct multipanel plots to different figures (files) while within a loop. Say, the loop creates two plots each step: one plot should go to figure 1 and the other to figure 2. Same for the next steps of the loop: the plots should go to figure 1 and figure 2 in a

Re: [R] looping multipanel plots to different figures

2015-02-19 Thread Jim Lemon
Hi efisio, I read this as wanting to start a new graphics device, then set some plot parameters, display two plots and then close the graphics device at each iteration of the loop. If so, plot_filenames-c(plot1.png,plot2.png,plot3.png) for(plotfn in plot_filenames) { png(plotfn)

Re: [R] looping multipanel plots to different figures

2015-02-19 Thread efisio solazzo
Thanks Jim, actually I need to keep open two devices at the same time, and within the loop access either of them in alternation. In MatLab there is the command Figure(#) which keeps track of the open devices and direct the output of the plot to whichever of them. For example:

Re: [R] looping multipanel plots to different figures

2015-02-19 Thread Jim Lemon
Hi efisio, Okay, you can switch devices using the dev.* functions in the grDevices package. If you only have two devices open at one time, this is not too difficult: #open both devices png(...) par(mfrow=c(1,2)) png(...) par(mfrow=c(1,2)) hist(...) dev.set(dev.next()) hist(...)

[R] looping in R

2014-04-02 Thread Abugri James
I ran the following loop on my SNP data and got an error message as indicated for (i in genenames){ + current - fst1[which(fst1$Gene == i),] + num - nrow(current) + fst - max(current$fst) + position - mean(current$pos) + nposition - mean(current$newpos) + numhigh -

Re: [R] looping in R

2014-04-02 Thread Jeff Newmiller
You desperately need to read the Posting Guide (mentioned in the footer of this email) which warns you not to post in HTML format, and learn how to make a reproducible example (e.g. http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). The problem lies in some

Re: [R] looping in R

2014-04-02 Thread Duncan Murdoch
On 02/04/2014, 3:15 PM, Abugri James wrote: I ran the following loop on my SNP data and got an error message as indicated I would assume that the error message is accurate: as.character(current[1, gene_old]) has length zero. You'll need to debug why that happened. Duncan Murdoch for (i

Re: [R] looping through 3D array

2014-01-11 Thread arun
Hi Alex, Not sure if this is what you wanted. length(res) #from the previous 'example' using ##indx - combn(dim(results)[1],2) #[1] 45 mat1 - matrix(0,10,10)  mat1[lower.tri(mat1)] - res  mat1[upper.tri(mat1)] - res A.K. On Saturday, January 11, 2014 12:22 AM, alex padron

Re: [R] looping through 3D array

2014-01-10 Thread apadr007
It seems like emdist does not like to compare matrices with all 0 values. I ended up removing those from my 3D array and have ~8000 matrices instead of 13000. I am using res2 - unlist(mclapply(seq_len(ncol(indx)),function(i) {x1 - indx[,i]; emd2d(results[x1[1],,],results[x1[2],,]) }) ) But even

Re: [R] looping through 3D array

2014-01-09 Thread arun
Hi, Try: library(emdist) set.seed(435) results- array(sample(1:400,120,replace=TRUE),dim=c(10,3,4)) res - sapply(seq(dim(results)[1]),function(i) {x1 - results[i,,]; x2 - results; sapply(seq(dim(x2)[1]),function(i) emd2d(x1,x2[i,,]))}) dim(res) #[1] 10 10 A.K. On Thursday, January 9, 2014

Re: [R] looping through 3D array

2014-01-09 Thread arun
Hi, No problem. You can use ?lower.tri() or ?upper.tri() res[lower.tri(res)] res[lower.tri(res,diag=TRUE)] #Other way would be to use: ?combn indx - combn(dim(results)[1],m=2) res2 - sapply(seq_len(ncol(indx)),function(i) {x1 - indx[,i]; emd2d(results[x1[1],,],results[x1[2],,]) })  

Re: [R] looping function through list

2014-01-02 Thread arun
Hi, May be this helps:  set.seed(42)  output1 - list(list(matrix(0,8,11),matrix(0,8,11)), list(matrix(rnorm(80),8,10),matrix(rnorm(80),8,10)))  library(emdist)  sapply(output1,function(x) {emd2d(x[[seq_along(x)[1]]],x[[seq_along(x)[2]]]) }) #[1]   NaN -6.089909 A.K. I'm trying to apply a

Re: [R] looping function through list

2014-01-02 Thread arun
#or  mapply(emd2d,sapply(output1,`[`,1),sapply(output1,`[`,2)) #[1]   NaN -6.089909 A.K. On Thursday, January 2, 2014 2:33 PM, arun smartpink...@yahoo.com wrote: Hi, May be this helps:  set.seed(42)  output1 - list(list(matrix(0,8,11),matrix(0,8,11)),

Re: [R] looping function through list

2014-01-02 Thread arun
HI, I tested it on R 3.0.2 console (linux) and also on Rstudio Version 0.98.490.  It seems alright. A.K.  Thanks for this. I am trying to run the code you posted but Rstudio keeps crashing. I am trying to run it on the example output1 since it's small but that crashes as well. On

Re: [R] looping through columns in a matrix or data frame

2014-01-01 Thread arun
Hi, May be this helps: Using your function: mapply(less,test,4) #or  invisible(mapply(less,test,4)) #[1] 2 3 #[1] 3 #or  for(i in 1:ncol(test)){  less(test[,i],4)} #[1] 2 3 #[1] 3 A.K. Hi, I'm trying to figure out how to loop through columns in a matrix or data frame, but what I've been

Re: [R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-13 Thread Mikkel Grum
You might want to try: assign(d[1], read.csv(yourfile.csv)) ... write.csv(d1, yourfile.csv, append = FALSE) Regards Mikkel On Friday, October 11, 2013 2:53 PM, Dan Abner dan.abne...@gmail.com wrote: Hi everybody, I thought I was using the get() fn correctly here to loop over multiple data

[R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-11 Thread Dan Abner
Hi everybody, I thought I was using the get() fn correctly here to loop over multiple data frame names in an R for() loop. Can someone advise? miss-c(#NULL!,999) d-c(d1,d2,d3,d4) for(i in 1:4){ + + miss1-ifelse(i=2,miss[1],miss[2]) + miss1 + +

Re: [R] Looping over names of multiple data frames in an R for() loop XXXX

2013-10-11 Thread jim holtman
I think you want 'assign' at that point. Would suggest using a 'list' to store the input instead of unique named objects. 'list's are easier to manage. Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On

Re: [R] Looping an lapply linear regression function

2013-09-06 Thread arun
HI, Using the example dataset (Test_data.csv): dat1- read.csv(Test_data.csv,header=TRUE,sep=\t,row.names=1) indx2-expand.grid(names(dat1),names(dat1),stringsAsFactors=FALSE) indx2New- indx2[indx2[,1]!=indx2[,2],] res2-t(sapply(seq_len(nrow(indx2New)),function(i) {x1- indx2New[i,];

Re: [R] Looping an lapply linear regression function

2013-09-05 Thread Flavio Barros
Hello Arun. Can you provide some data? To help you better i will need a complete reproducible example ok? On Thu, Sep 5, 2013 at 1:49 PM, arun smartpink...@yahoo.com wrote: HI, May be this helps: set.seed(28) dat1-

  1   2   3   >