[R] Loop stopping after 1 iteration
Hi all, This is a very basic question, but I just can't figure out why R is handling a loop I'm writing the way it is. Here is the script I have written: grid_2_series<-function(gage_handle,data_type,filename) series_name<-paste(gage_handle,data_type,sep="_") data_grid<-read.table(file=paste(filename,".txt",sep="")) num_rows_data<-nrow(data_grid)-1 num_cols_data<-ncol(data_grid)-4 num_obs<-num_rows_data*num_cols_data time_series<-matrix(nrow=0,ncol=2) for(i in 1:length(num_obs)){ rownum<-ceiling(i/31)+1 colnum<-if(i%%31==0){ 35 }else{ (i%%31)+4 } year<-data_grid[rownum,2] month<-data_grid[rownum,3] day<-colnum-4 date_string<-paste(month,day,year,sep="/") date<-as.Date(date_string,format='%m/%d/%Y') value<-as.character(data_grid[rownum,colnum]) time_series<-rbind(time_series,c(date,value)) } The script is working as I intended it to (goes through a matrix of data where column 2 is the year, column 3 is the month, and row 1 columns 5-35 are the day of the month the observation was recorded [I have included a screenshot below to help visualize what I'm talking about] and converts the grid into a 2 column time series where column 1 is the date and column 2 is the value of the observation), but it is stopping after only 1 iteration. nabble_img src="matrix_screenshot.jpg" border="0"/> Two questions: 1.) Does anyone know of an existing function to accomplish this task? 2.) Why is the loop stopping after 1 iteration? I have it written to iterate up to the total number of observations (20,615 in one case). Thank you for your help and sorry for this question which I'm sure has a very simple answer. Thanks again, Billy< -- View this message in context: http://r.789695.n4.nabble.com/Loop-stopping-after-1-iteration-tp3532988p3532988.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop stopping after 1 iteration
I knew it would be something simple. Thanks for catching that, Martyn. Billy -- View this message in context: http://r.789695.n4.nabble.com/Loop-stopping-after-1-iteration-tp3532988p3533041.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loop stopping after 1 iteration
Didn't mean to snub you guys, Hugo and David. I didn't see your posts before. Thanks for the advice. -- View this message in context: http://r.789695.n4.nabble.com/Loop-stopping-after-1-iteration-tp3532988p3533217.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] days between dates
Geoff, I think you could write an if loop to solve this. You could write: for(i in 1:num_obs){ if(DAYS[i]=='Monday'){ DF$DAYS.BETWEEN[i]<-1 } } Where 'num_obs' is the total number of temperature observations you have. This would only be correct if you had no missing data on Fridays. Also, if you had any missing Mondays, the Tuesday 'DAYS.BETWEEN' would be a 5 instead of a 2. Maybe there's a better way to do this, but I think this should work as long as you have a pretty complete record. Billy -- View this message in context: http://r.789695.n4.nabble.com/days-between-dates-tp3544335p3544643.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Difficulty with 'loess' function
Hi, I am trying to create a loess smooth from hydrologic data. My goal is to create a smooth line that describes discharge at a certain point in time. I have done this using the 'lowess' function and had no problem, but I'm having some difficulty with loess. I am inputting the date ('date') and discharge ('q') values using the 'scan' function, then inputting the following: > dateq<-data.frame(date,q) > dateq_smooth<-loess(dateq,span=.5) > dateq_smooth_pred<-predict(dateq_smooth,date) > dateq_smooth_pred [1] 1959.164 1959.516 1963.379 1967.121 1963.781 1970.601 1958.056 1948.846 1954.247 [10] 1954.718 1969.460 1960.974 1949.845 1962.436 1968.374 1954.247 1956.135 1948.852 [19] 1948.846 1957.893 1963.055 1955.327 1961.453 1960.405 1956.135 1963.065 1959.358 [28] 1954.478 1954.415 1964.323 1963.255 1953.139 1966.048 1959.353 1961.817 1959.894 [37] 1958.251 1964.914 1960.157 1964.656 1964.164 1949.873 1965.500 1968.323 1962.196 [46] 1961.656 1954.977 1969.196 1962.318 1952.576 1962.655 1968.031 1963.445 1967.856 [55] 1961.323 1949.032 1954.687 1955.613 1982.081 1960.736 1963.466 1974.468 1970.164 [64] 1954.212 1957.928 1957.893 1961.985 1966.180 1963.283 1963.379 1964.387 1970.017 [73] 1959.353 1969.925 1963.111 1962.667 1963.417 1964.029 1965.241 1964.323 1964.405 [82] 1963.036 1981.359 1968.146 1968.374 1970.050 1963.089 1959.667 1966.129 1958.081 [91] 1964.029 1968.374 1967.856 1955.758 1954.619 1965.227 This output is not what I'm looking for. It seems like maybe it's smoothing the date data instead of discharge? I tried messing around with other ways of inputting the data and I was getting errors about the input being type "text" and "double" or something like that. I read up on: http://research.stowers-institute.org/efg/R/Statistics/loess.htm http://research.stowers-institute.org/efg/R/Statistics/loess.htm but I was unable to figure out what I am doing wrong. Does anyone have any suggestions to offer? Thanks. Billy -- View this message in context: http://r.789695.n4.nabble.com/Difficulty-with-loess-function-tp3387537p3387537.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Difficulty with 'loess' function
Yeah, I did look at the help(loess) page, but I wasn't really sure what to do with that. I was inputting it as: > test<-loess(date ~ q,data.frame(date,q),span=0.5) > test Call: loess(formula = date ~ q, data = data.frame(date, q), span = 0.5) Number of Observations: 96 Equivalent Number of Parameters: 8.08 Residual Standard Error: 27.82 > check<-predict(test,date=date) > check [1] 1959.164 1959.516 1963.379 1967.121 1963.781 1970.601 1958.056 1948.846 [9] 1954.247 1954.718 1969.460 1960.974 1949.845 1962.436 1968.374 1954.247 [17] 1956.135 1948.852 1948.846 1957.893 1963.055 1955.327 1961.453 1960.405 [25] 1956.135 1963.065 1959.358 1954.478 1954.415 1964.323 1963.255 1953.139 [33] 1966.048 1959.353 1961.817 1959.894 1958.251 1964.914 1960.157 1964.656 [41] 1964.164 1949.873 1965.500 1968.323 1962.196 1961.656 1954.977 1969.196 [49] 1962.318 1952.576 1962.655 1968.031 1963.445 1967.856 1961.323 1949.032 [57] 1954.687 1955.613 1982.081 1960.736 1963.466 1974.468 1970.164 1954.212 [65] 1957.928 1957.893 1961.985 1966.180 1963.283 1963.379 1964.387 1970.017 [73] 1959.353 1969.925 1963.111 1962.667 1963.417 1964.029 1965.241 1964.323 [81] 1964.405 1963.036 1981.359 1968.146 1968.374 1970.050 1963.089 1959.667 [89] 1966.129 1958.081 1964.029 1968.374 1967.856 1955.758 1954.619 1965.227 > So I guess I'm inputting the formula wrong then? But from looking at the help(formula) page, I still wasn't sure what it's looking for. Thanks. Billy -- View this message in context: http://r.789695.n4.nabble.com/Difficulty-with-loess-function-tp3387537p338.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Difficulty with 'loess' function
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> That would certainly help, haha. Thank you for catching that error. Do you happen to know what exactly '~' means in R? Thanks again. Billy nblarson [via R] wrote: Flip date and q in your formula, you've got them backwards from what you've said you're trying to model. armstrwa wrote: Yeah, I did look at the help(loess) page, but I wasn't really sure what to do with that. I was inputting it as: > test<-loess(date ~ q,data.frame(date,q),span=0.5) So I guess I'm inputting the formula wrong then? But from looking at the help(formula) page, I still wasn't sure what it's looking for. Thanks. Billy If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Difficulty-with-loess-function-tp3387537p3388108.html To unsubscribe from Difficulty with 'loess' function, click here . -- William Armstrong Hydrology Research Assistant NOAA Restoration Center 55 Great Republic Drive Gloucester, MA 01930 email: william.armstr...@noaa.gov ph: 978-675-2181 -- View this message in context: http://r.789695.n4.nabble.com/Difficulty-with-loess-function-tp3387537p3388273.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Kendall v MannKendall Functions
Hi, I am running a correlation analysis on a temporal dataset. I was wondering if you would receive the same tau and p values running the function: MannKendall(x), where x is the dependant variable that changes with time as you would running: Kendall(d,x), where x is the exact same dataset as the x entered into MannKendall and d is the date on which the observation was made (assuming that the order is the same as the data I entered into the Kendall function). Can anyone elucidate this for me? Thanks. Billy -- View this message in context: http://r.789695.n4.nabble.com/Kendall-v-MannKendall-Functions-tp3394821p3394821.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Basic Looping Trouble
Hi all, Forgive me for this basic question. I've been doing some research and haven't been able to figure out how to best do this yet. I have 75 variables defined as vector time series. I am trying to create a script to automate calculations on each of these variables, but I wasn't sure how to go about calling variables in a script. I am hoping to write a loop that calls a list of variable names and runs several tests using each of the datasets I have entered. For example, say I have a defined 5 variables: var1, var2,...var5. How could I create a script that would run, say, a MannKendall correlation test on each variable? Thank you very much, and again, sorry for the rudimentary question. Billy -- View this message in context: http://r.789695.n4.nabble.com/Basic-Looping-Trouble-tp3394860p3394860.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Looping Problem
Hi all, I am trying to write a script that will automate the task of running a Kendall's Tau correlation test on 75 time series that I am interested in. The code I have written is: for(i in 1:length(gagehandles)){ dates<-get(paste(gagehandles[i],"_amsd",sep="")) q<-get(paste(gagehandles[i],"_amsq",sep="")) taup<-Kendall(dates,q) print(gagehandles[i]) print(taup) So basically, I have inputted all the records I am concerned with into R using the scan function. These are all represented by a four letter identifier followed by _amsd or _amsq (to distinguish the two variables). For example, a variable might be hoea_amsd, which has a corresponding hoea_amsq. I am trying to write a function that will run through a list of the gage identifiers ('gagehandles' in the code) and will then runn and Kendall's tau correlation test on the two variables (suffixes '_amsd' and '_amsq'). It was working when I was using a small subset of my data, but now that I am trying to look at all 75 series, I am getting the error: Error in get(paste(gagehandles[i], "_amsd", sep = "")) : variable names are limited to 256 bytes It didn't have a problem with the variable names before, so I'm not sure what's going on now. Does anyone have an idea? Thank you very much for your help. Billy -- View this message in context: http://r.789695.n4.nabble.com/Looping-Problem-tp3397077p3397077.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Kendall v MannKendall Functions
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> Thank you very much, Peter. That does make it clearer. Billy Peter Ehlers [via R] wrote: On 2011-03-21 14:16, armstrwa wrote: > Hi, > > I am running a correlation analysis on a temporal dataset. I was wondering > if you would receive the same tau and p values running the function: > > MannKendall(x), where x is the dependant variable that changes with time > > as you would running: > > Kendall(d,x), where x is the exact same dataset as the x entered into > MannKendall and d is the date on which the observation was made (assuming > that the order is the same as the data I entered into the Kendall function). > > Can anyone elucidate this for me? > Assuming that you're referring to the (unstated) package Kendall, a quick look at the code for MannKendall tells you that MannKendall(x) just does Kendall(1:length(x), x). Does that answer your question? Peter Ehlers __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Kendall-v-MannKendall-Functions-tp3394821p3395771.html To unsubscribe from Kendall v MannKendall Functions, click here . -- William Armstrong Hydrology Research Assistant NOAA Restoration Center 55 Great Republic Drive Gloucester, MA 01930 email: william.armstr...@noaa.gov ph: 978-675-2181 -- View this message in context: http://r.789695.n4.nabble.com/Kendall-v-MannKendall-Functions-tp3394821p3397082.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Basic Looping Trouble
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> Thanks, Petr. Your insight has helped me out a lot. Billy Petr Savicky-2 [via R] wrote: On Mon, Mar 21, 2011 at 02:28:32PM -0700, armstrwa wrote: > Hi all, > > Forgive me for this basic question. I've been doing some research and > haven't been able to figure out how to best do this yet. > > I have 75 variables defined as vector time series. I am trying to create a > script to automate calculations on each of these variables, but I wasn't > sure how to go about calling variables in a script. > > I am hoping to write a loop that calls a list of variable names and runs > several tests using each of the datasets I have entered. > > For example, say I have a defined 5 variables: var1, var2,...var5. How > could I create a script that would run, say, a MannKendall correlation test > on each variable? Hi. A typical way, how to perform a loop over several variables, is to keep the variables in a list. For example lst <- list(var1=2:5, var2=c(23, 56), var3=seq(0, 1, length=11)) lst $var1 [1] 2 3 4 5 $var2 [1] 23 56 $var3 [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 for (i in seq.int(along=lst)) { print(mean(lst[[i]])) } [1] 3.5 [1] 39.5 [1] 0.5 It is also possible to loop over isolated variables. For example var1 <- 2:5 var2 <- c(23, 56) var3 <- seq(0, 1, length=11) for (varnam in c("var1", "var2", "var3")) { x <- get(varnam) print(mean(x)) } Hope this helps. Petr Savicky. __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Basic-Looping-Trouble-tp3394860p3395690.html To unsubscribe from Basic Looping Trouble, click here . -- William Armstrong Hydrology Research Assistant NOAA Restoration Center 55 Great Republic Drive Gloucester, MA 01930 email: william.armstr...@noaa.gov ph: 978-675-2181 -- View this message in context: http://r.789695.n4.nabble.com/Basic-Looping-Trouble-tp3394860p3397087.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Magic Number Error Message
Hi all, When I attempt to run a script, I keep getting the error message shown below. I have seen from searching that the "Use of save versions prior to 2 is deprecated" could be an error resulting from a permissions problem, but I have been unable to find anything describing the "file has magnic number '# Coh'". The file I am attempting to read into the script is a text file that contains 3 columns of data, if that makes a difference. Does this seem to be a permissions problem, as well, or is there something else going wrong? I'm sorry, but I can't post the script file because the colleague who gave it to me asked that I not distribute it yet, but it has worked for him, so I don't think that there is something wrong with the script itself -- it seems like there is something wrong on my end. Thank you for your help. Billy > load("H:\\Restoration Center\\Climate Change and > Restoration\\MidAtlFloodRisk\\discharge data\\R files\\ALRT.txt") Error: bad restore file magic number (file may be corrupted) -- no data loaded In addition: Warning message: file 'ALRT.txt' has magic number '# Coh' Use of save versions prior to 2 is deprecated -- View this message in context: http://r.789695.n4.nabble.com/Magic-Number-Error-Message-tp3405414p3405414.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Magic Number Error Message
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> Thanks, Philipp. That helped a lot. I have run into another problem now though. I am running the script, and some of it seems to work, but it outputs all NAs for the data and I get 50+ error warnings saying: Warning messages: 1: unable to compute correlation matrix; maybe change 'h' 2: unable to compute correlation matrix; maybe change 'h' 3: unable to compute correlation matrix; maybe change 'h' 4: unable to compute correlation matrix; maybe change 'h' and on and on.. Does anyone know what might be causing this error? Or is there a way for me to see what line in the code results in an error? Thanks again. Billy Philipp Pagel-5 [via R] wrote: On Fri, Mar 25, 2011 at 06:42:49AM -0700, armstrwa wrote: > When I attempt to run a script, I keep getting the error message shown > > load("H:\\Restoration Center\\Climate Change and > > Restoration\\MidAtlFloodRisk\\discharge data\\R files\\ALRT.txt") > Error: bad restore file magic number (file may be corrupted) -- no data > loaded > In addition: Warning message: > file 'ALRT.txt' has magic number '# Coh' >   Use of save versions prior to 2 is deprecated The load() function reads stored DATA into the workspace. As you say you want to run a SCRIPT you are probably looking for source(). cu     Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/ __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Magic-Number-Error-Message-tp3405414p3405445.html To unsubscribe from Magic Number Error Message, click here . -- William Armstrong Hydrology Research Assistant NOAA Restoration Center 55 Great Republic Drive Gloucester, MA 01930 email: william.armstr...@noaa.gov ph: 978-675-2181 -- View this message in context: http://r.789695.n4.nabble.com/Magic-Number-Error-Message-tp3405414p3405726.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Acessing Test Outputs for Writing to a Table
Hi all, I am trying to write a script that will compute Kendall's tau for a 75 time series (using the Kendall package) and will then write the tau and p values from the Kendall test to a text file table that can be read into Excel. I am having no problem calculating Kendall's tau and the associated p value for each time series, but I am having trouble figuring out how aggregate the results from all the the time series into one table. For one thing, the tau and p outputs from the Kendall function don't seem to be variables that have been created in the workspace (i.e. if i type 'tau' in the command line, i get an error saying "Error: object 'tau' not found"). Is there a way I can access these values to write them to a table? When I try to write the output of the Kendall function to a table using 'write.table' I get this error message: Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : cannot coerce class '"Kendall"' into a data.frame Secondly, once I am able to access the tau and p values, what would be the best to write into the loop function to add the tau and p values calculated from each iteration of the loop to a table? Thank you. Billy -- View this message in context: http://r.789695.n4.nabble.com/Acessing-Test-Outputs-for-Writing-to-a-Table-tp3412743p3412743.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Paste problem when looping variable assignments
Hi all, I am attempting to run through a large set of data and sort events by the water year (1 Oct - 30 Sep) in which they occurred. I have no problem doing this for each individual site I am looking at (so my problem is not with most of the code, just one minor thing), but when I try to loop it to do the same things for each site, I run into problems. I think the root of my problem is that I am trying to switch the name of a variable for each iteration of the loop. I am using a paste function on the left side of a "<-" statement, which R doesn't seem to like. I am trying to create a variable for each site I am looking at (with the format "sitename_pdswy") that contains how many events occurred in a given year, which I want to use in further calculations. I keep getting the following error message: Error in paste(pds_gagehandles[[i]], "_pdswy", sep = "") <- POTWY_cut : could not find function "paste<-" Does anyone know how I might be able to do this? It seems like the type of thing that must have a simple solution that I am just overlooking.. I have posted my entire code below, with the problematic line bolded and italicized. Thank you very much for your help. Billy full code: for(i in 1:length(pds_gagehandles)){ dates<-get(paste(pds_gagehandles[i],"_pds_rawd",sep="")) q<-get(paste(pds_gagehandles[i],"_pds_rawq",sep="")) yr<-as.numeric(strftime(dates,format='%Y')) mo<-as.numeric(strftime(dates,format='%m')) len<-length(yr) for(n in 1:len){ WY[n]<-if(mo[n]>=10){ yr[n]+1 }else{ yr[n]} } partialpeakind<-which(round(q,2)>=round(pds_TD[i],2)) partialpeaksd<-dates[partialpeakind] partialpeaksq<-q[partialpeakind] partialpeaksWY<-WY[partialpeakind] for(q in 1:length(partialpeaksWY)){ wyrs<-seq(min(partialpeaksWY),max(partialpeaksWY),by=1) POTWY[[q]]<-sum(partialpeaksWY == wyrs[q]) POTWY_cut<-as.numeric(na.omit(POTWY)) paste(pds_gagehandles[[i]],"_pdswy",sep="")<-POTWY_cut} pds_dropdates<-data.frame(partialpeaksWY,partialpeaksd,partialpeaksq) write.table(pds_dropdates,file=paste(pds_gagehandles[i],"_dropdates.txt",sep="")) write.table(data.frame(wyrs,POTWY_cut),file=paste(pds_gagehandles[i],"_POTWY.txt",sep="")) } -- View this message in context: http://r.789695.n4.nabble.com/Paste-problem-when-looping-variable-assignments-tp3468414p3468414.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Paste problem when looping variable assignments
One thing I should have mentioned before is that "pds_gagehandles" is a character vector that contains the site names that I am interested in. An example of a site name is "saho". So with with the paste function, I am trying to get R to assign a variable with the site name followed by "_potwy". For example, I am trying to create a vector of events/year named "saho_potwy". Thanks again. Billy -- View this message in context: http://r.789695.n4.nabble.com/Paste-problem-when-looping-variable-assignments-tp3468414p3468429.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.