Re: [R] Problem with Plotting in R

2018-12-19 Thread MacQueen, Don via R-help
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

Re: [R] Different performance with different R versions

2018-12-12 Thread MacQueen, Don via R-help
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

Re: [R] How to create gridded data

2018-11-14 Thread MacQueen, Don via R-help
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

Re: [R] missRanger package

2018-11-12 Thread MacQueen, Don via R-help
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.

Re: [R] Remove specific rows from nested list of matrices

2018-11-02 Thread MacQueen, Don via R-help
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

Re: [R] Speeding up R code - Apply a function to each row of a matrix using the dplyr package

2018-11-01 Thread MacQueen, Don via R-help
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).

Re: [R] Plot a path

2018-10-31 Thread MacQueen, Don via R-help
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

Re: [R] Gamma Simulation from Exponential Distribution: find sample size given power and sig.Level

2018-10-29 Thread MacQueen, Don via R-help
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

Re: [R] "logical indexing, " [was] match() question or needle haystack problem for a data.frame

2018-10-29 Thread MacQueen, Don via R-help
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

Re: [R] date and time data on x axis

2018-10-29 Thread MacQueen, Don via R-help
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

Re: [R] Genuine relative paths with R

2018-10-08 Thread MacQueen, Don via R-help
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

Re: [R] How can I create a loop for this? Please help me

2018-10-05 Thread MacQueen, Don via R-help
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

Re: [R] Sp-package overlay

2018-10-03 Thread MacQueen, Don via R-help
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

Re: [R] From for loop to lappy?

2018-10-01 Thread MacQueen, Don via R-help
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

Re: [R] Printing standard notation and scientific notation in the same column of a dataframe

2018-09-27 Thread MacQueen, Don via R-help
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

Re: [R] Access function as text from package by name

2018-09-27 Thread MacQueen, Don via R-help
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,

Re: [R] Summarizing R script

2018-09-26 Thread MacQueen, Don via R-help
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

Re: [R] For Loop

2018-09-24 Thread MacQueen, Don via R-help
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

Re: [R] How to vectorize this function

2018-09-20 Thread MacQueen, Don via R-help
ve., 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-help" wrote

Re: [R] How to vectorize this function

2018-09-20 Thread MacQueen, Don via R-help
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" :

Re: [R] as.Date and ylim in empty plot

2018-09-19 Thread MacQueen, Don via R-help
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

Re: [R] Applying by() when groups have different lengths

2018-09-17 Thread MacQueen, Don via R-help
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

Re: [R] Applying by() when groups have different lengths

2018-09-17 Thread MacQueen, Don via R-help
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

Re: [R] New to R

2018-09-14 Thread MacQueen, Don via R-help
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

Re: [R] sink() output to another directory

2018-09-13 Thread MacQueen, Don via R-help
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

Re: [R] histogram in GNU R....

2018-09-07 Thread MacQueen, Don via R-help
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

Re: [R] Display time of PDF plots

2018-09-05 Thread MacQueen, Don via R-help
(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

Re: [R] r-data partitioning considering two variables (character and numeric)

2018-08-27 Thread MacQueen, Don via R-help
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) ) grp[mydata$stand_ID

Re: [R] r-data partitioning considering two variables (character and numeric)

2018-08-27 Thread MacQueen, Don via R-help
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)

Re: [R] Multiple counters in a single for loop

2018-08-24 Thread MacQueen, Don via R-help
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

Re: [R] plotmath and logical operators?

2018-08-20 Thread MacQueen, Don via R-help
cell 925-724-7509 From: Bert Gunter Date: Monday, August 20, 2018 at 3:38 PM To: "MacQueen, Don" Cc: array R-help Subject: Re: [R] plotmath and logical operators? This is clumsy and probably subject to considerable improvement, but does it work for you: left <- quote(x >= 3)

[R] plotmath and logical operators?

2018-08-20 Thread MacQueen, Don via R-help
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

Re: [R] Understanding read.csv error message

2018-08-17 Thread MacQueen, Don via R-help
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,

Re: [R] Understanding read.csv error message

2018-08-17 Thread MacQueen, Don via R-help
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

[R] Using rmarkdown with many plots created in a loop

2018-08-16 Thread MacQueen, Don via R-help
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

Re: [R] searching for a specific row name in R

2018-08-15 Thread MacQueen, Don via R-help
Lab cell 925-724-7509 From: Deepa Date: Monday, August 13, 2018 at 8:36 PM To: "MacQueen, Don" , array R-help Subject: Re: [R] searching for a specific row name in R Hi Don, When there is a list of identifier names that I want to check, the only way is to loop over each entry stor

Re: [R] searching for a specific row name in R

2018-08-13 Thread MacQueen, Don via R-help
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

Re: [R] Resolving installed package updates warning

2018-08-10 Thread MacQueen, Don via R-help
even look at the other error messages until that one has been solved. -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/10/18, 9:53 AM, "R-help on behalf of Rich Shepard" wrote: On Fri, 1

Re: [R] Resolving installed package updates warning

2018-08-10 Thread MacQueen, Don via R-help
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

Re: [R] Help reinstalling rgdal (Ubuntu 16.04)

2018-08-09 Thread MacQueen, Don via R-help
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

Re: [R] error with the expand.grid command

2018-08-09 Thread MacQueen, Don via R-help
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: >

Re: [R] Plot function: hourly data and x-axis

2018-08-09 Thread MacQueen, Don via R-help
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

Re: [R] Combinations of true/false values where one pair is mutually exclusive

2018-08-02 Thread MacQueen, Don via R-help
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 <-

Re: [R] read txt file - date - no space

2018-07-30 Thread MacQueen, Don via R-help
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

Re: [R] Formatting summary() output to a file

2018-07-27 Thread MacQueen, Don via R-help
ehalf of Rich Shepard" wrote: On Fri, 27 Jul 2018, MacQueen, Don wrote: > Given your description, I would start with > > sink('wysumallyrs.txt') > print( summary(wyallyrs) ) > sink() > > and see if that doesn't meet your needs.

Re: [R] Formatting summary() output to a file

2018-07-27 Thread MacQueen, Don via R-help
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().

Re: [R] SQL Database

2018-07-26 Thread MacQueen, Don via R-help
ight drivers that might be appropriate for centos, but if anyone happens to know, hints are appreciated Harold -Original Message----- From: MacQueen, Don [mailto:macque...@llnl.gov] Sent: Thursday, July 26, 2018 11:26 AM To: Doran, Harold ; 'r-help@r-project.org'

Re: [R] SQL Database

2018-07-26 Thread MacQueen, Don via R-help
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

Re: [R] A couple of batch mode questions

2018-07-25 Thread MacQueen, Don via R-help
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

Re: [R] optim function

2018-07-13 Thread MacQueen, Don via R-help
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:

Re: [R] (no subject)

2018-07-11 Thread MacQueen, Don via R-help
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

Re: [R] R couldnt recognize US Pasific timezome

2018-07-09 Thread MacQueen, Don via R-help
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

Re: [R] inconsistency in display of character vector....

2018-07-08 Thread MacQueen, Don via R-help
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 <-

Re: [R] trouble with exiting loop if condition is met

2018-06-28 Thread MacQueen, Don via R-help
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

Re: [R] as.Date and Legend in a plot

2018-06-22 Thread MacQueen, Don via R-help
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

Re: [R] numeric comparison error

2018-06-18 Thread MacQueen, Don via R-help
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

Re: [R] subsetting lists....

2018-06-18 Thread MacQueen, Don via R-help
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

Re: [R] rgdal in 3.5 fails(?)

2018-06-15 Thread MacQueen, Don via R-help
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

Re: [R] Calling r-scripts with arguments from other scripts, or possibly R programming conventions/style guide

2018-06-13 Thread MacQueen, Don via R-help
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

Re: [R] Time and date conversion

2018-06-06 Thread MacQueen, Don via R-help
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

Re: [R] Time-series moving average question

2018-06-01 Thread MacQueen, Don via R-help
-- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 From: Bill Poling Date: Friday, June 1, 2018 at 10:43 AM To: "MacQueen, Don" , array R-help Subject: RE: [R] Time-series moving average question Hi Don

Re: [R] Time-series moving average question

2018-06-01 Thread MacQueen, Don via R-help
arning comes from the second step. Print tnr.ma and you will see some NAs. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509   From: Bill Poling Date: Friday, June 1, 2018 at 8:58 AM To: "MacQueen, Don"

Re: [R] Time-series moving average question

2018-06-01 Thread MacQueen, Don via R-help
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

Re: [R] how to make the code more efficient using lapply

2018-05-25 Thread MacQueen, Don via R-help
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

Re: [R] Manipulation of data.frame into an array

2018-05-24 Thread MacQueen, Don via R-help
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:

Re: [R] Loop Function to Create Multiple Scatterplots

2018-05-21 Thread MacQueen, Don
Here is a simplified example: dat <- data.frame(x=1:4, y1=runif(4), y2=runif(4), y3=4:1) for (icol in 2:4) plot(dat[,1] , dat[,icol] ) (not tested, so hopefully all my parentheses are balanced, no typos, etc.) This shows the basic principle. An alternative is to construct each column name as

Re: [R] add one variable to a data frame

2018-05-11 Thread MacQueen, Don
; wrote: Um, maybe just dat1$C <- match(dat1$B, unique(dat1$B)) Indexing 1:k with numbers between 1 and k is a bit of a no-op... AFAICT, this even works without stringsAsFactors=FALSE -pd > On 11 May 2018, at 21:30 , MacQueen, Don <

Re: [R] add one variable to a data frame

2018-05-11 Thread MacQueen, Don
Interesting comments, and they serve as a reminder that so much depends on: -- what is known or can be assumed about the structure of the incoming data -- what will be done with the data next (and is this a one-time effort, or will it be repeated multiple times with similarly-structured but

Re: [R] add one variable to a data frame

2018-05-11 Thread MacQueen, Don
Sarah's solutions are good, and here's another, even more basic: tmp1 <- unique(dat1$B) tmp2 <- seq_along(tmp1) dat1$C <- tmp2[ match( dat1$B, tmp1) ] > dat1 N B C 1 1 29_log 1 2 2 29_log 1 3 3 29_log 1 4 4 27_cat 2 5 5 27_cat 2 6 6 1_log 3 7 7 1_log 3 8 8 1_log 3 9

Re: [R] the first name of the first column

2018-05-10 Thread MacQueen, Don
And more helpful, probably, would have been the str() function: > str(mtcars) 'data.frame': 32 obs. of 11 variables: $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... $ disp: num 160 160 108 258 360 ... $ hp : num 110 110 93 110 175 105

Re: [R] the first name of the first column

2018-05-10 Thread MacQueen, Don
I think you are confusing row names with the first column. The first column in mtcars is not alphanumeric: > class(mtcars) [1] "data.frame" > class(mtcars[,1]) [1] "numeric" > rownames(mtcars) [1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710" "Hornet 4 Drive" "Hornet

Re: [R] using for loop with data frames.

2018-05-10 Thread MacQueen, Don
Evidently, you want your loop to create new data frames, named (in this example) df_selected1 df_selected2 df_selected3 Yes, it can be done. But to do it you will have to use the get() and assign() functions, and construct the data frame names as character strings. Syntax like

Re: [R] Seasonal weekly average

2018-05-09 Thread MacQueen, Don
I would just add, see ?strptime for information about those date format specifications ( "%V" for example), and an introduction to R's handling of date and date-time values. And a few quick examples, to see that %V works as advertised: > format( Sys.Date() , '%V') [1] "19" > format(

Re: [R] Dinamic variables in loop

2018-05-09 Thread MacQueen, Don
In addition to which, the original question uses an incorrect way to reference columns in the data frame. It should probably have been: newMyData <-MyData[!is.na(MyData$col1) | !is.na(MyData$col2) | !is.na(MyData$col3) | !is.na(MyData$col4) | !is.na(MyData$col5) , ] That is assuming that

Re: [R] help with json data from the web into data frame in R

2018-05-09 Thread MacQueen, Don
Regarding the question: From the linux shell I use the "-k" switch with cURL to ignore cert errors.. is there an equivalent in the R world? I have (sometimes) had success by creating a .curlrc file and putting the necessary curl options in it. When R invokes curl, curl picks up the

Re: [R] why the length and width of a plot region produced by the dev.new() function cannot be correctly set?

2018-05-04 Thread MacQueen, Don
But: > dev.new(height=10,width=10) > dev.size('in') [1] 10 10 Whereas > dev.new(length=10,width=10) > dev.size('in') [1] 10 7 Obviously, because height was not specified, some default calculation was used to set the height. And length was ignored. And thanks to Duncan Murdoch for pointing

Re: [R] How to visualise what code is processed within a for loop

2018-04-30 Thread MacQueen, Don
94550 925-423-1062 Lab cell 925-724-7509 From: Luca Meyer <lucam1...@gmail.com> Date: Monday, April 30, 2018 at 8:08 AM To: Rui Barradas <ruipbarra...@sapo.pt> Cc: "MacQueen, Don" <macque...@llnl.gov>, array R-help <r-help@r-project.org> Subject: Re: [R] How t

Re: [R] Copy text from Script syntax into .txt

2018-04-25 Thread MacQueen, Don
Try putting this options(echo=TRUE) at the beginning of your script See ?source for a clue -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 4/24/18, 2:23 AM, "R-help on behalf of P. Roberto

Re: [R] How to visualise what code is processed within a for loop

2018-04-25 Thread MacQueen, Don
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

Re: [R] Doubt_merging data

2018-04-09 Thread MacQueen, Don
Your email is hard to read because you sent html email. Please send plain text. You will need to say what you mean by "join". It's not a standard term with a universally agreed upon meaning within R. If you have 5 data frames, each with 5 rows, and it makes sense that after joining you should

Re: [R] Creating the right table from lapply list

2018-03-28 Thread MacQueen, Don
Perhaps this toy example will help: ## example data output <- list(1:5, 1:7, 1:4) lens <- lapply(output, length) maxlen <- max(unlist(lens)) outputmod <- lapply(output, function(x, maxl) c(x, rep(NA, maxl-length(x))), maxl=maxlen) outputmat <- do.call(cbind, outputmod) write.csv(outputmat,

[R] Adding a table of contents to html output using the bookdown package

2018-02-21 Thread MacQueen, Don
I am trying to get rmarkdown with bookdown to include a table of contents in html output, and having trouble. Here is an example that I think illustrates the trouble. I have a file "test.Rmd" as follows: [127]% cat test.Rmd --- title: Test Document output: html_document: toc: true ---

Re: [R] Package sgd

2018-02-05 Thread MacQueen, Don
For that matter, a simple within-browser search for "gradient" on the CRAN packages-by-name webpage, finds Gradient Descent for Regression Tasks Holonomic Gradient Method and Gradient Descent Continuous Generalized Gradient Descent And a few more that might or might not be relevant.

Re: [R] Concatening two maps/shapefiles...

2018-02-05 Thread MacQueen, Don
I would try using the xlim, ylim arguments in your first map() command, and then using the add argument in the second one. See the help page for the map function. This assumes that the map() function you are using comes from the maps package. Otherwise, perhaps you should be using the rgdal

Re: [R] Error while working with png output on linux server

2018-02-01 Thread MacQueen, Don
What does capabilities() return? For example, I get > capabilities() jpeg pngtiff tcltk X11 TRUETRUETRUETRUETRUE aquahttp/ftp sockets libxmlfifo TRUETRUETRUE

Re: [R] Help in Plotting in "fArma" Package

2018-01-26 Thread MacQueen, Don
What Dave said, plus here's a hint. Try this example (which uses base graphics): plot(1:5) plot(1:5, cex.lab=2) Then look at the help page for par help('par') or ?par to search for other graphics parameters (base graphics) you can use to change various things. Success will depend, as

Re: [R] Packages couldn't load

2018-01-19 Thread MacQueen, Don
Or the openxlsx package, which does not require Java, and is similar to the xlsx package in functionality (both reads and writes, for example). -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 1/16/18,

Re: [R] HOW TO FILTER DATA

2018-01-04 Thread MacQueen, Don
Just a couple of minor comments: > help.search('read_delim') No vignettes or demos or help files found with alias or concept or title matching 'read_delim' using regular expression matching. read_delim is not part of base R; it must come from some unnamed non-base package. I'd recommend using

Re: [R] something weird has happened....!!!!!!!!!!

2017-12-15 Thread MacQueen, Don
You could try this and see what you get: unique( yguii(ZEEL.NS, "o") - yguii(ZEEL.NS, "o") ) or maybe table( yguii(ZEEL.NS, "o") - yguii(ZEEL.NS, "o") ) You showed two sets of output from the expression yguii(ZEEL.NS, "o") Were they done one right after the other? Or could ZEEL.NS

Re: [R] Errors in reading in txt files

2017-12-14 Thread MacQueen, Don
In addition to which, I would recommend df <- read.table("DATAM", header = TRUE, fill = TRUE, stringsAsFactors=FALSE) and then converting the Time column to POSIXct date-time values using as.POSIXct() specifying the format using formatting codes found in ?strptime because the times are not

Re: [R] difference between ifelse and if...else?

2017-12-13 Thread MacQueen, Don
Because ifelse is not intended to be an alternative to if ... else. They exist for different purposes. (besides the other replies, a careful reading of their help pages, and trying the examples, should explain the different purposes). -- Don MacQueen Lawrence Livermore National Laboratory 7000

Re: [R] Fwd: Wanted to learn R Language

2017-11-30 Thread MacQueen, Don
And if you have trouble with read.export(), then another option is to use SAS to export the data to a text file, then load it into R using R's read.table() function. I would suggest that the SAS export be to a tab-delimited file, with column headers, and no quotes around text fields, but there

Re: [R] Scatterplot of many variables against a single variable

2017-11-27 Thread MacQueen, Don
Here's the quickest way I know of to get a scatterplot of many variables against a single variable. I create example data to illustrate. x <- 1:10 ys <- matrix( runif(30), ncol=3) matplot(x,ys) ## or, a little better, matplot(x,ys, type='b') To add regression lines: for (iy in seq(ncol(ys)))

Re: [R] Converting a string to variable names

2017-11-17 Thread MacQueen, Don
Do you mean that you have One data frame, and it has a bunch of variables within it named P1, P2, P3... or A bunch of data frames names P1, P2, P3... ? I'll assume it's the latter. Here is one way: dfnms < c('P1', 'P2', 'P3') for (nm in dfnms) { tmp <- get(nm) rownames(tmp) <-

Re: [R] Convert poly line to polygon in R

2017-11-16 Thread MacQueen, Don
In addition to which, the rgeos package may have something. If it's just a single polyline, it may be pretty easy to pull out the coordinates as a two column matrix, append the first row at the end, and rebuild it as a polygon. The readOGR function in the rgdal package is probably a better

Re: [R] R-help

2017-11-09 Thread MacQueen, Don
A trip to the Spatial Task View on CRAN might be in order. The RandomFields package comes to mind. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 11/9/17, 12:37 AM, "R-help on behalf of PIKAL Petr"

Re: [R] How to save and restore a workspace

2017-10-25 Thread MacQueen, Don
Saving your workspace means that the variables you currently have defined in your session [ everything that shows up when you type ls() ] are saved to a file, by default named “.RData”. To restore the workspace, you use the “Load Workspace” command and navigate to the (same) .RData file. Its

Re: [R] working with ordinal predictor variables?

2017-10-05 Thread MacQueen, Don
Try looking at the help page for factor ?factor for something to start with. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab cell 925-724-7509 On 10/5/17, 10:54 AM, "R-help on behalf of Alexandra Thorn"

Re: [R] Converting SAS Code

2017-09-29 Thread MacQueen, Don
For the initial data step, assuming a data frame named stress already exists, and using base R, you can start with something like this: barcodes.to.delete <- c('16187DD4015', '16187DD6002', {complete the comma-delimited vector of barcodes you don't want} ) yield <- subset(stress, !(barcode

Re: [R] build a SpatialLines object from a list

2017-09-27 Thread MacQueen, Don
Have you tried following the example in ?'SpatialLines-class' You'll probably get better help from R-sig-geo And please don't send html email, it makes your email hard to read. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 Lab

  1   2   3   4   5   6   >