Displaying 20 results from an estimated 20000 matches similar to: "replace a for loop"
2005 Dec 01
2
Minimizing a Function with three Parameters
Hi,
I'm trying to get maximum likelihood estimates of \alpha, \beta_0 and
\beta_1, this can be achieved by solving the following three equations:
n / \alpha + \sum\limits_{i=1}^{n} ln(\psihat(i)) -
\sum\limits_{i=1}^{n} ( ln(x_i + \psihat(i)) ) = 0
\alpha \sum\limits_{i=1}^{n} 1/(psihat(i)) - (\alpha+1)
\sum\limits_{i=1}^{n} ( 1 / (x_i + \psihat(i)) ) = 0
\alpha \sum\limits_{i=1}^{n} (
2010 Feb 04
5
export test results to csv
Hi everybody!
I would like to export the results of a test statistic in a *.csv file,
but get an error.
The code is below.
The data are attached as .txt with tab as separator. I tried to get a
sample dataset, but for some reason it didn't work, so please excuse the
length of the file. I also attached a txt with the output (copy/paste)
in case that helps.
----
> library(WRS)
>
2010 May 19
3
save in for loop
Dear users,
My problem concerns save() within a for loop.
Here is my code:
for (i in 1:4) {
temp <- data.frame(a=(i+1):(i+10), b=LETTERS[(i+1):(i+10)])
filename <- paste("file", i, sep="")
assign(filename, temp)
save(filename, file=paste(filename, ".rda", sep=""))
}
As you can see, save() doesn't work as I would like: (1) the object
2010 Nov 01
2
number of items to replace is not a multiple of replacement length
Hey all,
I am writing a function in which I will have a matrix of 4 columns and a
variable amount of rows.
The first to columns will always contain be of the Character type, the third
and fourth columns
can be a variation of data types, usually characters and integers, but
sometimes lists or matrices.
At one point the code makes, for each row, a copy of that row, then it makes
some adjustments
2010 May 20
1
use object within rda file in for loop
Dear users,
I would like to process all the lists from all *.rda files that I have
in one folder.
Up to now, I can load all the *.rda files without any problem.
The problem is when I want to access the list saved within each *.rda
file (only one list per rda file).
Here is my code:
fpath <- "D:/R"
listnames <- list.files(path=fpath, pattern=glob2rx("*.rda"),
2012 Mar 22
1
Replace sub string
Given:
> filename<-paste(tempdir(),"\\","myfile.txt",sep="");
> sub("\\\\","/",filename);
[1] "C:/DOCUME~1\\AJAYAS~1\\LOCALS~1\\Temp\\Rtmp2f270T\\myfile.txt"
Note: Only the first occurence of \\ is replaced. What is the syntax for replacing every occurence?
Thanks.
[[alternative HTML version deleted]]
2010 Sep 16
5
using variable from for loop in naming new variables
Simple one here ... but can't get it to work ...
for (i in 1:4){
paste("stuff",[i]),sep="") <- 3 + i
}
ls()
rm(list=ls())
I just want it to create 4 new variables called stuff1, stuff2, stuff3, stuff4 with the corresponding assignments. I realise that there are more elegant functions but this is just a model of a bigger situation.
Thanks
Jim
2010 May 28
2
Re : help to replace variable value
Dear All,
I have a data frame "data" with Jan , Feb as column. I using like this
data$Jan to take Jan column. I have the Jan in another variable
var1 <- "Jan"
data$var1
I need to replace the variable value there . Any help will be greatly
appreciated.
Thanks & Rg
Mohan L
[[alternative HTML version deleted]]
2012 Jul 25
2
old weird error message
Dear users,
I have a weird questions. A friend of mine, some years ago, supposedly
trying to access help files without Internet connection, got something
like this error message:
"The Pythia is not available, please go to Delphi"
When I've heard about it, I found it very funny and I'd like to be able
to get it. Does anyone of you know how to get this error message again?
2013 Jan 23
2
importing data
Dear All,
Sorry for asking a newbie question. I want to ask how to import 1000
datasets whose file names are labelled from data1.dat to data1000.dat into
R so that they are named M[1, , ] to M[1000, , ] accordingly. Thank you
very much.
Best Regards,
Ray
[[alternative HTML version deleted]]
2011 Apr 10
1
Help with basic loop
The loop is correct, you just need to make sure that your result is computed
and stored as the n-th element that is returned by the loop. Pick up any
manual of R, and looping will be explained there. Also, I would recommend
that you draw a random number for every iteration of the loop. Defining the
random vectors outside the loop make sense to me only if they are the same
length as n.
2010 Feb 16
2
for loop Vs apply function Vs foreach (REvolution enhancement)
Dear all,
I know this topic has already been covered in other posts (at least the for loop Vs apply family of function), but I am looking for fresh / up-to-date opinion and feedback on those 3 methods to run unavoidable loops in R. I realise that it may be too general question for many, so any feedback appreciated.
1. apply Vs for loop
>> Seems apply is (was?) supposed to be faster than
2010 Oct 29
1
Simulating data, loop
Hello,
I would like to run a script in which a loop is included. Since I'm new to
R, I cannot manage the following problem. I really hope someone could help
me out.
Data in the variable Y should be removed from the simulated data set with
probability 0.50 if the variable X has a value below zero, and with
probability 0.10 if X has a value above zero (see script).
However, the total number of
2010 Sep 21
2
labels in (box)plot
Dear users,
I would like all the ticks on a boxplot (x and y) to be labeled
I have checked all the par() arguments but couldn't find what I'm
looking for
Here is an example to show it:
df <- structure(list(SPECSHOR = structure(c(1L, 1L, 1L, 3L, 3L, 3L, 3L,
3L, 4L, 4L), .Label = c("cotau", "dibic", "eqgre", "gicam"), class =
2010 Mar 11
3
Help function "?" in R 2.10.1
Hello everyone,
I have versions 2.7.2 and 2.10.1 installed on a machine that has no
access to internet.
In 2.7.2 I can use ? to get help on functions, which in 2.10.1 that
does not work, all I see is "starting httpd help server...done" and
then nothing.
Have I downloaded 2.10.1 incorrectly (=forgot to tick some box for
local help file repository) or is the internet help now the
2011 Apr 20
2
user input
Dear users,
I have looked on different sources and found different functions to
prompt the user to provide input. However, I couldn't find one that does
exactly what I'm looking for.
select.list() and menu() are nice because a graphic window appears to
prompt the user. However, the user can only choose from a predefined
list of choices. readline() and scan() are more free in the
2010 May 18
3
"Re: Change class factor to numeric"
sorry I had a mistake sending my question without a subject. I do resend again. Please excuse me.
> Hello
> I have a data array with soil variables (caperf), in which the variable "clay" is factor (as I see entering str(caperf)) . I need to do a regression model, so I need to have arcilla (=clay) as a numeric variable. For that I have entered
>
>
2011 Feb 24
3
problem in for loop
Hi all.
I was having some trouble with a for loop and I found the problem is the
following.
Does anyone have some idea why I got the following R result? Since mone
is equal to 3, why
mu1 only have 2 components?
library(MASS)
> p0 <- seq(0.1, 0.9,by=0.1)
> m <- 10
>
>
> p0 <- p0[7]
>
> ## data generation
>
> mzero <- p0*m
> mone <- m-mzero
>
2010 May 28
3
Using a loop to define new variables
Hi,
I'm a novice R user, much more used to SAS. My problem is pretty simple - basically, in a data frame, I have variables named
x1,....,x10 and y1,...,y10; and I would like to create r1 = x1 / y1 etc
Apologies if this is way too rudimentary - but I couldn't find any posts online which solve this exact issue.
Cheers,
Andre
2010 May 20
2
Overlap of leaf labels
Hi,
I have tried looking at the archives but havent found any answer that works
till now (Sorry if i have missed anything)
I am a newbie to R and i am trying to carry out hierarchical clustering
using hclust -> as.dendrogram and then plotting the results as a dendrogram
using the plot function plot(object).
My question is :
In the function "plot", can one decrease the leaf label