Displaying 20 results from an estimated 10000 matches similar to: "for loop help"
2010 Sep 07
5
how to you output a vector to a column in excel?
What is the syntax for this?
If you have: vector = c(1,2,3,4), how would you output this to column A of
an excel spreadsheet?
--
View this message in context: http://r.789695.n4.nabble.com/how-to-you-output-a-vector-to-a-column-in-excel-tp2530470p2530470.html
Sent from the R help mailing list archive at Nabble.com.
2010 Sep 14
3
extracting objects from lists
If you have 5 data frames and you append them to a list, how do you access
the first data frame, not the first value of the first data frame while
iterating in a for loop?
list = c(d1,d2,d3,d4,d5) where d1..d5 are dataframes.
for(i in 1: length(list)){
print(list[1])
}
--
View this message in context: http://r.789695.n4.nabble.com/extracting-objects-from-lists-tp2539412p2539412.html
Sent from
2010 Sep 06
2
how do I transform this to a for loop
arima1 = arima(data.ts[1:200], order = c(1,1,1))
arima2 = arima(data.ts[5:205], order = c(1,1,1))
arima3 = arima(data.ts[10:210], order = c(1,1,1))
arima4 = arima(data.ts[15:215], order = c(1,1,1))
arima5 = arima(data.ts[20:220], order = c(1,1,1))
arima6 = arima(data.ts[25:225], order = c(1,1,1))
arima7 = arima(data.ts[30:230], order = c(1,1,1))
arima8 = arima(data.ts[35:235], order = c(1,1,1))
2010 Sep 05
8
R time series analysis
I have a data file with a given time series of price data and I would like to
split the time series into a test set and training set. I would then like to
build an ARIMA model on the training set and apply this model on test set.
Below is some code:
[CODE]
data= read.table("A.txt",sep=",")
attach(data)
training = data[1:120, 6]
test = data[121:245, 6]
ts1 = ts(training)
ts2 =
2010 Oct 03
5
How to iterate through different arguments?
If I have a model line = lm(y~x1) and I want to use a for loop to change the
number of explanatory variables, how would I do this?
So for example I want to store the model objects in a list.
model1 = lm(y~x1)
model2 = lm(y~x1+x2)
model3 = lm(y~x1+x2+x3)
model4 = lm(y~x1+x2+x3+x4)
model5 = lm(y~x1+x2+x3+x4+x5)...
model10.
model_function = function(x){
for(i in 1:x) {
}
If x =1, then the list
2010 Oct 17
4
how to convert string to object?
temp = "~aparch("
temp1 = paste(temp,1, sep = "")
temp2 = paste(temp1,1, sep = ",")
temp3 = paste(temp2, ")",sep = "")
temp 3 is a character but I want to convert to formula object. How do I do
this?
--
View this message in context: http://r.789695.n4.nabble.com/how-to-convert-string-to-object-tp2999281p2999281.html
Sent from the R help mailing
2010 Nov 03
2
How to unquote string in R
s= "Hey"
a = "Hello"
table = rbind(s,a)
write.table(table,paste("blah",".PROPERTIES",sep = ""),row.names =
FALSE,col.names = FALSE)
In my table, how do I output only the words and not the words with the
quotations?
--
View this message in context: http://r.789695.n4.nabble.com/How-to-unquote-string-in-R-tp3025654p3025654.html
Sent from the R
2012 Jul 11
4
Help with loop
Hi,
I have two dataframes:
The first, df1, contains some missing data:
cola colb colc cold cole
1 NA 5 9 NA 17
2 NA 6 NA 14 NA
3 3 NA 11 15 19
4 4 8 12 NA 20
The second, df2, contains the following:
cola colb colc cold cole
1 1.4 0.8 0.02 1.6 0.6
I'm wanting all missing data in df1$cola to be replaced by the value of
df2$cola.
2009 Jul 27
1
Creating new data frame using loop
Hi all,
I sent a request round last week asking for help with using a "for" loop to read and separate a large dataset. The response I got worked great, but now I have another problem with using my loop.
Basically I have a number of different files containing columned data. There are 132 datasets, named such that I have something in the form...
precip_colxxx.txt
...where xxx is a
2005 Jan 19
2
Referencing objects within a loop
Dear List:
It appears that simulating data where all dataframes are stored as a
list will only work for relatively small analyses. Instead, it appears
that creating N individual dataframes, saving them, and loading them
when needed is the best way to save memory and make this a feasible
task.
As such, I now have a new(er) question with respect to dealing with
individual files within a loop. To
2018 Apr 28
2
How to visualise what code is processed within a for loop
Thanks Don,
for (i in 1:10){
nm <- paste0("V", i)
d0[[nm]] <- ifelse( regexpr(d1[i,1], d0$X0) > 0, 1, 0)
}
is exaclty what I needed.
Best regards,
Luca
2018-04-25 23:03 GMT+02:00 MacQueen, Don <macqueen1 at llnl.gov>:
> Your code doesn't make sense to me in a couple of ways.
>
> Inside the loop, the first line assigns a value to an
2018 Apr 28
0
How to visualise what code is processed within a for loop
Hello,
instead of ifelse, the following is exactly the same and much more
efficient.
d0[[nm]] <- as.integer(regexpr(d1[i,1], d0$X0) > 0)
Hope this helps,
Rui Barradas
On 4/28/2018 8:45 PM, Luca Meyer wrote:
> Thanks Don,
>
> for (i in 1:10){
> nm <- paste0("V", i)
> d0[[nm]] <- ifelse( regexpr(d1[i,1], d0$X0) > 0, 1, 0)
> }
2018 Apr 25
0
How to visualise what code is processed within a for loop
Your code doesn't make sense to me in a couple of ways.
Inside the loop, the first line assigns a value to an object named "t".
Then, the second line does the same thing, assigns a value to an object named "t".
The value of the object named "t" after the second line will be the output of the ifelse() expression, whatever that is. This has the effect of making
2018 Apr 28
2
How to visualise what code is processed within a for loop
I forgot to explain why my suggestion.
The logical condition returns FALSE/TRUE that in R are coded as 0/1.
So all you have to do is coerce to integer.
This works because the ifelse will return a 1 or a 0 depending on the
condition. Meaning exactly the same values. And is more efficient since
ifelse creates both vectors, the true part and the false part, and then
indexes those vectors in
2018 Apr 30
0
How to visualise what code is processed within a for loop
Hi Rui
Thank you for your suggestion,
I have tested the code suggested by you against that supplied by Don in
terms of timing and results are very much aligned: to populate a 5954x899
0/1 matrix on my machine your procedure took 79 secs, while the one with
ifelse employed 80 secs, hence unfortunately not really any significant
time saved there.
Nevertheless thank you for your contribution.
2010 Oct 07
1
how to convert list to language object
If I have a list:
list = c(~garch(1,1), ~arma(1,1)) and I run
typeof(list[1]), the output is a list object. But I want each element in the
list to be a language object. How do I transform these list objects to
language objects?
--
View this message in context: http://r.789695.n4.nabble.com/how-to-convert-list-to-language-object-tp2966813p2966813.html
Sent from the R help mailing list archive at
2012 Apr 30
2
for loop problem
Hi all,
I was wondering if you can help me with the following situation:
I have a data frame that includes weather station data for 30 years in
the form:
YEAR, MONTH, DAY, TEMP
1970, 01, 01, -15
...
1999, 12, 31, -21
I would like to add another variable "JULIAN" that assigns the integers
1 to 365 (and 1 to 366 for leap years) for each day of a year over
multiple years.
Here is what
2006 Mar 30
2
'loop FOR' for make plots
Hello
How to create plots dynamically with results of several analysis ?
I got many outputs from lm fuction like:
mp1.lm mp2.lm mp3.lm mp4.lm mp5.lm ...
I'd like to make experimental versus predicted response plots of all
analysis
in a 'for loop':
for( i in 1:10){
x11()
plot( mp*i*$experimental_response, fitted( mp*i* ) ); abline(0,1)
}
I tried: paste( 'mp', i,
2018 Apr 30
0
How to visualise what code is processed within a for loop
Thank you for both replies Don & Rui,
The very issue here is that there is a search that needs to be done within
a text field and I agree with Rui later comment that regexpr might indeed
be the time consuming piece of code.
I might try to optimise this piece of code later on, but for the time being
I am working on the following part of building a neural network to try
indeed classifying some
2018 Apr 24
4
How to visualise what code is processed within a for loop
Hi,
I am trying to debug the following code:
for (i in 1:10){
t <- paste("d0$V",i,sep="")
t <- ifelse(regexpr(d1[i,1],d0$X0)>0,1,0)
}
and I would like to see what code is actually processing R, how can I do
that?
More to the point, I am trying to update my variables d0$V1 to d0$V10
according to the presence or absence of some text (contained in the file
d1)