You haven't described what you are trying to get with the command that doesn't
work. My guess is that this might be what you want:
plot( x, MyData$NWorth, type="l" )
lines( x, MyData$NWorthSm)
However, you might also have to calculate and supply a for the ylim argument to
plot(
Probably more appropriate for R-SIG-Mac
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 12/11/18, 12:22 AM, "R-help on behalf of cowan robin"
wrote:
I am running a small simulation, and getting ver
Sarah's answer is probably the best approach, but to do it using very basic R
methods that predate the very good spatial support that R now has, I would
likely do this:
## Thanks, Jim Lemon, for this step:
df1 <- read.table(text=
"latitude longitude Precip
45.5 110.5 3.2
45
I could not find the word "censor" in the documentation for the missRanger
package, so I think additional explanation is needed.
Also, I would expect information about censoring to be included in data
provided to a function in a package -- inserting censoring into a package
doesn't make sense.
It appears that at the bottom of the nesting, so to speak, you have a character
matrix.
That is, the contents of the [[1]][[1]][[1]] element is a character matrix
that, according to the row and column labels, has 4 rows and 5 columns.
However, the matrix itself, as printed, has, apparently, 4 col
Without more study, I can only give some general pointers.
The as.vector() in X1 <- as.vector(coord[1]) is almost certainly not needed. It
will add a little bit to your execution time.
Converting the output of func() to a one row matrix is almost certainly not
needed. Just return c(res1, res2).
Probably
sort the data frame by date
Then
plot( mydf$geogr.longitude, mydf$geogr.latitude, type='l')
Search the web for some tutorials
See the help pages for
plot
plot.default
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
If this is homework, then r-help has a no homework policy. I'm assuming that if
it is homework then the focus is on statistical concepts, not on R programming.
It looks like your gen_p_vals function should be defined as
gen_p_vals <- function(reps = n)
instead of n = reps.
Why not just use
Wrong comparisons, I think.
The opposite of
A & B
is
!(A & B)
There is no single operator that can replace the "&" in A & B that gives the
"opposite"
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
Here's an example of 24 hours of data at one second intervals.
npts <- 24*60*60
df <- data.frame(
tm = seq( Sys.time(), by='1 sec', length=npts),
yd = round(runif(npts),2)
)
head(df)
with(df, plot(tm,yd))
The x axis appears to me to be display
A few facts (and some opinions):
First fact:
R understands relative paths (as do the other languages you mentioned) (you
have misunderstood R if you think it doesn't)
Second fact:
R interprets relative paths as being relative to its current working directory
Third fact:
To find out R'
Bert (in his separate email) is right about learning the basics, and using
R-sig-geo. You're kind of jumping right into the deep end! None the less,
here's an example that should help.
For one thing, you're being more complicated than necessary.
SpatialPointsDataFrame objects can, much of the t
In addition, the function you want is
sp::over
or its equivalent in sf
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 10/2/18, 1:41 PM, "R-help on behalf of Ben Tupper"
wrote:
Hi,
I'm pr
Try
A <- lapply(file.names, function(fn) extract_tables(fn)
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 10/1/18, 3:32 PM, "R-help on behalf of Ek Esawi"
wrote:
Hi All—
I am using Tabu
First compare
> format(c(0.52, 0.17, 0.03, 1e-20))
[1] "5.2e-01" "1.7e-01" "3.0e-02" "1.0e-20"
> prettyNum(c(0.52, 0.17, 0.03, 1e-20))
[1] "0.52" "0.17" "0.03" "1e-20"
>
If you want to print one column at a time, that will do what you ask. If you
want to print the entire data frame, with num
Or
sink('stuff.txt') ; graphics::box ; sink()
to have it in a text file.
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 9/27/18, 4:55 AM, "R-help on behalf of Rui Barradas"
wrote:
Hello,
I wonder if the lintr package might be helpful.
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 9/26/18, 7:00 AM, "R-help on behalf of Spencer Brackett"
wrote:
R users,
Is anyone aware o
In my opinion this is a pretty reasonable question for someone new to R.
Yes, it can be written without a for loop, and it would be better. Rich
Heiberger gave a good solution early on, but I'd like to add an outline of the
reasoning that leads to the solution.
You are taking the log of a ratio
ory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 9/20/18, 12:36 PM, "Jeff Newmiller" wrote:
re: your last comment... why do you prefer to multiply by the reciprocal?
On September 20, 2018 10:56:22 AM PDT, "MacQueen, Don via R-hel
In addition to what the other said, if callM is a vector then an expression of
the form
if (callM <= call0)
is inappropriate. Objects inside the parentheses of if() should have length
one. For example,
> if (1:5 < 3) 'a' else 'b'
[1] "a"
Warning message:
In if (1:5 < 3) "a" else "b" :
th
I'm a little surprised at some of what happens, but you can get date labels on
the x axis like this:
drng <- as.Date( c('2005-1-1' , '2005-12-31') )
plot(1, type="n", xlab="", ylab="", xaxt='n', xlim=drng, ylim=c(-.5, -10))
axis(1, at= pretty(drng), lab=format(pretty(drng)))
and if you prefer so
I'm also going to guess that maybe your object
rainfall_by_site
has already been split into separate data frames (because of its name).
But by() does the splitting internally, so you should be passing it the
original unsplit data frame.
You could supply example data by providing the first few
Try changing it to
by(rainfall_by_site, rainfall_by_site[, 'name'],
function(x) {mean.rain <- mean(x[, 'prcp'])
})
Inside the function, so to speak, the function sees an object named "x",
because that's how the function is defined: function(x).
So you have to operate on x inside
If l.out is not a data frame, what is it? A list? A matrix? Some other
structure? Try
str(l.out)
class(l.out)
and see what you get.
Can't help you convert it to a data frame without knowing what it is.
After you have a data frame, then write.table(), write.csv(), or write.csv2()
will "con
In my experience, any path that can be used at the shell prompt in a unix-alike
can be used anywhere that R wants a file name.
[that is, when running R on a unix-alike system, and when pwd at the shell
prompt returns the same value as getwd() in R]
Hopefully, that helps...
-Don
--
Don MacQue
In addition to the other suggestions, try typing
x11()
before using hist().
That *should* start a graphics window. If it does not, then type
capabilities()
and see if "X11" is TRUE.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-
(this is somewhat a change of subject from the original question)
Rich, there functions such as aggregate() in base R. There are also many
options in CRAN packages.
But I tend to have difficulty getting them to do exactly what I want, and
usually end up rolling my own.
The idea is to split the
n
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 8/27/18, 4:10 PM, "R-help on behalf of MacQueen, Don via R-help"
wrote:
You could start with split()
grp <- rep('', nrow(mydata) )
You could start with split()
grp <- rep('', nrow(mydata) )
grp[mydata$stand_ID %in% c(7,9,67)] <- 'A-training'
grp[mydata$stand_ID %in% c(3,18,20,21,32)] <- 'B-testing'
split(mydata, grp)
or perhaps
grp <- ifelse( mydata$stand_ID %in% c(7,9,67) , 'A-training', 'B-testing' )
split(mydata, grp)
I don't know of any such option, but it's easy enough to achieve something more
or less equivalent.
x <- runif(5)
for (ir in seq(nrow(myi <- cbind(x, 1:length(x) {
i <- myi[ir,1]
j <- myi[ir,2]
cat(i,j,'\n')
}
I consider that for() statement to be ugly and unreadable. Normally I would
t, right = right)))
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 County" comic strip )
On Mon, Aug 20, 2018 at 2:00 PM MacQueen, Don via R-help
mailto:
I would like to use plotmath to annotate a plot with an expression that
includes a logical operator.
## works well
tmp <- expression(x >= 3)
plot(1)
mtext(tmp)
## not so well
tmp <- expression(x >= 3 & y <= 3)
plot(1)
mtext(tmp)
Although the text that's displayed makes sense, it won't be obvi
small typo in previous: should be
quote=""
(I left behind a single quote by mistake)
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 8/17/18, 5:03 PM, "R-help on behalf of MacQueen,
Hi Rich,
It's not obvious what would be causing that error from read.csv. But here's
what I would probably try:
Add quote='"" to your arguments. The default is to use surround text strings
with double quotes, but your file doesn't.
Copy the first few rows into another file and try it. If it su
I would appreciate some suggestions of a good way to prepare a report using
rmarkdown,
in which I loop through subsets of a data set, creating a plot of each subset,
and interspersing
among the figures some text relevant to each figure.
One way is to have an R script write the rmd file, then ren
It depends on what you want to check. There are a lot of things you can check
without looping.
For example, if you want to check whether all of the first letters of the
identifier names are "A", you could do
table( substr(idnames,1,1))
to show you all of the first letters, and how many there a
Or to return a logical value, i.e., TRUE if the column contains the value,
FALSE if it does not:
any( x[,2] == 'A501' )
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 8/13/18, 12:09 AM, "R-help o
Rich,
C++11 is a programming language.
Interestingly, someone else asked for help yesterday with exactly the same
error message for rgdal. The subject line was
"Help reinstalling rgdal (Ubuntu 16.04)"
The suggestions were to visit the mailing lists R-sig-geo and/or R-sig-debian.
It's puzzli
I would start by trying to install rgdal by itself, rather than as part of a
"batch" update. As in
Install.packages('rgdal')
My expectation is that you will see a more complete error message specific to
rgdal, which presumably will provide a clue or pointer.
-Don
--
Don MacQueen
Lawrence L
There are quite a few messages on R-sig-geo about installing rgdal on Ubuntu.
Maybe one of them contains your solution?
(I use Mac, so can't help directly)
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
In my experience, error messages that reference a closure usually mean that you
have supplied a function where you aren't supposed to.
In this case, I'd look and see if lon, lat, or time is a function (by accident,
of course).
More specifically, right now in one of my R sessions, I get:
> clas
Normally, one turns off the x-axis tick marks and labels by supplying
xaxt='n' in the plot() call, and then adds a customized x-axis using the
axis() function.
But without more information, little help can be provided (a vague question
receives a vague answer).
I'd suggest reviewing the pos
From what I can tell, the simplest way is to
First generate all the combinations
Then exclude those you don't want.
Here's an example, with only three variables (D, E, and F), that excludes those
where E and F both fail
> tmp <- c('p','f')
> X <- expand.grid(D=tmp, E=tmp, F=tmp)
> X <- sub
Or, without removing the first line
dadf <- read.table("xxx.txt", stringsAsFactors=FALSE, skip=1)
Another alternative,
dadf$datetime <- as.POSIXct(paste(dadf$V1,dadf$V2))
since the dates appear to be in the default format.
(I generally prefer to work with datetimes in POSIXct class rather tha
Hmmm. I do get output in the file with the first example, and the second
example is too complicated for me.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 7/27/18, 9:56 AM, "R-help on behalf of Rich
Given your description, I would start with
sink('wysumallyrs.txt')
print( summary(wyallyrs) )
sink()
and see if that doesn't meet your needs.
Some of the basic principles:
(1) Whenever you type the name of an R object at the R prompt, it is as if R
wraps whatever you typed inside print(). Here
Harold,
I don't have much experience with ODBC/RODBC, but given that it's working on
Win, a driver problem seems plausible.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 7/26/18, 9:37 AM, "Doran,
From my point of view, the logic is this:
If the external database is Oracle, use ROracle
If the external database is MySQL, use RMySQL
and similarly for other databases
If there is no R package specific to the database, then you drop back to RODBC
or RJDBC. Hopefully you can get the necessa
From my perspective, which is a unix-alike perspective, Rscript makes R useable
in exactly the same way as other unix style scripting languages such as perl,
tcsh, bash, etc. This is useful, and a good thing. If I remember (and
understood) correctly, it is why Rscript was introduced, later in R
There's a CRAN Task View on optimization. There might be something useful there.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 7/13/18, 11:43 AM, "R-help on behalf of Federico Becerra"
wrote:
Maybe I missed it, but I didn't see anyone suggest a visit to the CRAN Spatial
task view. This would be a good place to start learning how to work with
spatial data in R.
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell
Or (perhaps preferably) "US/Pacific" for daylight savings time support.
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 7/9/18, 1:46 AM, "R-help on behalf of Jeff Newmiller"
wrote:
Several of the "c
In addition to what Ben and Jeff have said, I think you can simplify your
function considerably. See these examples:
> substr( c('abc', 'abcd','abcde') , c(2,1,3), c(2,2,4))
[1] "b" "ab" "cd"
> foo <- c('abc', 'abcd','abcde')
> substr( foo , 1, nchar(foo)-2)
[1] "a" "ab" "abc"
> foo <- c('
Does this example help?
> for (ii in 1:10) { cat( ii,'\n') ; if (ii >3) break }
1
2
3
4
The loop won't stop unless you tell it to stop, and I don't see any place where
you told it to stop.
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-42
What David Winsemius said, plus:
Does
legend('topleft', c("Climax", "Thule", "Sopo"), lty = 1, col =
("black","red","blue"))
not work?
It should, which will illustrate that you CAN add a legend to the plot.
The x,y that you supply to legend must be values that are within the x,y range
of the
What Jeff, said, plus to see it explicitly:
> print(cpgbins[5:7], digits=18)
[1] 0.200011 0.25 0.300044
> print(c(0.2, 0.25, 0.3), digits=18)
[1] 0.200011 0.25 0.299989
-Don
--
Don MacQueen
Lawrence Livermore Nation
The unlist solution is quite clever.
But I will note that none of the solutions offered so far succeed if the input
is, for example,
YH <- list(1:5, letters[1:3], 1:7)
iuhV <- c(2,2,4)
and the desire is to return a list whose elements are of the same types as the
input list. Which would
In case no one else has made the suggestion yet, take this question to
R-sig-geo, where there has already been discussion and sharing of information
and experiences about this.
You'll need to include the output of sessionInfo().
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000
When I want to run multiple scripts one after the other, and have variables
created in a script be still in memory for use by a subsequent script, I
normally create a master script (say, "runall.r") and it sources each of the
others in turn. For example, my master script (runall.r) would look li
After you've solved the format inconsistency issues, per Peter's advice, you
will need to understand that R internally converts and stores the timedate
values in UTC. Therefore, it is absolutely essential to give it the correct
timezone specification on input.
The user does not "convert to UTC
For your first question, you’re doing moving averages of 3 points (I assume
that’s what order=3 does). For any given time point of your input data, that
would be one before, one at, and one after the given time point. Do all of
your input times have both one before and one after?
Don’t know ab
You are right that there are no NAs in the practice data. But there are NAs in
the moving average data.
To see this, break your work into two separate steps, like this:
tnr.ma <- ma(dat3[1:28], order=3)
TNR_moving_average <- forecast(tnr.ma, h=8)
I think you will find that the warning comes
My guess would be that if you inspect the output from
ma(dat3[1:28], order=3)
you will find some NAs in it. And then forecast() doesn't like NAs.
But I can't check, because I can't find the ma() and forecast() functions. I
assume they come from some package you installed; it would be helpful
Eric's approach seems reasonable to me, and I agree that it's probably not the
use of a "for" loop that makes the original version slow. As Eric mentioned,
there are lots of unnecessary things happening in the loop.
For example, list.files() was called twice inside the loop, which is
unnecessar
It would help if you show exactly the structure of your desired result, using
the simple example data you supplied (what, exactly, do you mean by "array"?)
If you want mydata[[1]] "to provide the values for all three 3 variables (Y, X1
and X2) of the first imputation only" then this will do it:
65 matches
Mail list logo