I am hitting an odd message "Error in FUN(newX[, i], ...) : all arguments must
have the same length". I can't supply the data as it's a huge data frame but I
think this has enough diagnostic information to show the issue. I am sure I am
missing something obvious. I've put some extra comments
Your code is full of syntactic errors. What do you think 1.71(se) means?
After you clean up your code, something like this might be what you want:
out <- lapply(seq(40,500,by = 25), f)
To get plots, just stick in a plot statement after you define m and d.
Have you gone through any R tutorials?
1. 2o is gibberish; 20 is the number of fingers and toes most of us have.
2. This is a plain text list. Your code became gibberish with your HTML
post.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Be
Hi,
I have the below function which returns confidence intervals. I wanted to pass
different sample sizes through the function, but for some reason it's not
working. n <- seq(from=40, to=300, by=2o)
I was also wondering how I can return a plot for different sample sizes.
plot(m~d, main="
Yes.
Beating a pretty weary horse, a slightly cleaner version of my prior
offering using with(), instead of within() is:
with(dat,
dat[sampleNo[sample(var1[!var1%%2 & !sampleNo], 10, rep=FALSE)],
"sampleNo"] <- 2)
with() and within() are convenient ways to avoid having to repeatedly name
the col
Dear Rich,
Assuming that I understand what you want to do, try adding the following to
your script (which, by the way, is more complicated that it needs to be):
xx <- 10:50
m <- lm(y ~ x)
yy <- predict(m, data.frame(x=xx))
lines(spline(xx, yy), col="blue")
m <- lm(y ~ log(x))
yy <- predict(m, d
Hello,
Please run the following code snippet and note the resulting plot:
x <- c(10, 50)
y <- c(0.983, 0.7680123)
plot(x,y,type="b",log="x")
for(i in 1:50){
xx <- exp(runif(1,log(min(x)),log(max(x)) ))
yy <- approx(x,y,xout=xx, method = "linear")
points(xx,yy$y)
}
notice the "log=x" plot pa
Hi David,
I was about to post a reply when Bert responded. His answer is good
and his comment to use the name 'dat' rather than 'data' is instructive.
I am providing my suggestion as well because I think it may address
what was causing you some confusion (mainly to use "which", but also
the missing
For personal aesthetic reasons, I changed the name "data" to "dat".
Your code, with a slight modification:
set.seed (1357) ## for reproducibility
dat <- data.frame(var1=seq(1:40), var2=seq(40,1))
dat$sampleNo <- 0
idx <- sample(seq(1,nrow(dat)), size=10, replace=F)
dat[idx,"sampleNo"] <-1
## yi
Hello everybody!
I have the following problem: I'd like to select a sample from a subsample
in a dataset. Actually, I don't want to select it, but to create a new
variable sampleNo that indicates to which sample (one or two) a case
belongs to.
Lets suppose I have a dataset containing 40 cases:
d
1. Familiarize yourself with CRAN and the R homeage:
https://www.r-project.org/
2. https://www.r-project.org/bugs.html
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom Co
Once you have assigned the variable, it does not change unless you change it.
If you want to draw random numbers repeatedly, put the code into a function:
rnd <- function() {.35 * (runif(1, min=.81, max=1.03) + runif(1, min=1.06,
max=1.17) + runif(1, min=-.26, max=1.38)) +
.30 * (runif(1, mi
Hi Ashraf,
It is not obvious to me what your structures are but one problem in your
function is the assignment tt1 <- SpatialLines(list(tt[[i]])).
This will set tt1 to just have one item.
Consider the following
test.func <- function(x) {
tt1 <- list()
for ( i in ... ) {
...
I am attempting to write a code that will generate a win probability for a
hockey team. To do this, I have a code built that will generate a number of
random variables between two standard deviations, and then weight them and add
them together. However, when I attempt to assign this code to a va
Hi all,
I noticed that there was some confusion regarding a few statements in the R
documentation. There are multiple questions on Stackoverflow regarding
this. So I thought it may be helpful for other new users to add a small
example to clarify the statements.
I am wondering how I can suggest th
Hi all,I'm trying to build a SpatialLines object from a list that contains 124
river segments. Each segment in the list contains the x,y coordinates. I'm
using the following code to create the SpatialLines object, but it just
retrieves one segment. Any suggestions?
test.func = function(x){
You realize, do you not, that in fact there are no numbers in your "list"
(actually a vector).
It looks like you would do well to spend some time with an R tutorial or
two before posting further to this list. We can help, but cannot substitute
for the basic knowledge that you would gain from doin
Super, thanks Boris. Top notch :-)
On Mon, Sep 25, 2017 at 1:05 PM, Boris Steipe
wrote:
> Always via logical expressions. In this case you can use the logical
> expression
>
> myDF$b != "0"
>
> to give you a vector of TRUE/FALSE
>
>
>
> B.
>
>
> > On Sep 25, 2017, at 8:00 AM, Shane Carey wrote
Always via logical expressions. In this case you can use the logical expression
myDF$b != "0"
to give you a vector of TRUE/FALSE
B.
> On Sep 25, 2017, at 8:00 AM, Shane Carey wrote:
>
> This is super, really helpfull. Sorry, one final question, lets say I wanted
> to remove 0's rather t
This is super, really helpfull. Sorry, one final question, lets say I
wanted to remove 0's rather than NAs , what would it be?
Thanks
On Mon, Sep 25, 2017 at 12:41 PM, Boris Steipe
wrote:
> myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"),
>b = c("<0.1", 1, 0.3, 5, "Nil")
myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"),
b = c("<0.1", 1, 0.3, 5, "Nil"),
stringsAsFactors = FALSE)
# you can subset the b-column in several ways
myDF[ , 2]
myDF[ , "b"]
myDF$b
# using the column, you make a logical vector
! is.na(as.numeric(myDF
Hi,
Lets say this was a dataframe where I had two columns
a <- c("<0.1", NA, 0.3, 5, "Nil")
b <- c("<0.1", 1, 0.3, 5, "Nil")
And I just want to remove the rows from the dataframe where there were NAs
in the b column, what is the syntax for doing that?
Thanks in advance
On Fri, Sep 22, 2017 at
Hello,
Try using hist argument 'prob = TRUE' or, which is equivalent, 'freq =
FALSE'.
hist(..., prob = TRUE) # or hist(..., freq = FALSE)
This is because like this you will have a density, comparable to a
parametric density. Note that the peak of the normal will be outside the
plot area s
23 matches
Mail list logo