Re: [R] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread Jim Lemon
Hi Nevil, It's a nasty piece of work, but: M<-matrix(c(1,2,3,4,1,2,3,4,1,2,3,4,2,1,3,2),4,4, dimnames = list(NULL, c("x", "y", "z","k"))) M reprow<-function(x) return(matrix(rep(x,x[length(x)]),nrow=x[length(x)],byrow=TRUE)) toseq<-function(x) return(1:x) j<-unlist(sapply(M[,"k"],toseq)) Mlist<-a

Re: [R] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread nevil amos
OK sorted - hope these postings might help someone else Any even faster options would be appreciated still #seq() does not work but sequence() does print("rep and sequence") print(system.time({ j<-NULL MOut<-NULL MOut<-M[rep(1:nrow(M), times = M[,4]), ] j<-sequence(M[,4]) MOut<-cbind(M

Re: [R] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread nevil amos
Well, I found a way to do it partly using rep(), and one loop that makes it 10x or more faster however would still be good to do without the loop at all matrix made slightly beigger (1 rows): M<-matrix(c(1:3 ), 1,3) M<-cbind(M,sample(1:5,size = 1,replace = T)) #Print(M) #Create mat

Re: [R] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread Jeff Newmiller
False premise: rep works fine Mout2 <- cbind(M[ rep(seq.int(nrow(M)),M[,"k"]), c("x","y","z")],unlist(lapply(M[,"k"],seq.int))) On March 31, 2020 6:18:37 PM PDT, nevil amos wrote: >Hi > >I can achieve this using two for loops but it is slow I need to do >this on >many matrices with tens of mil

[R] repeat rows of matrix by number (k) in one colummatrix adding column j with values 1:k

2020-03-31 Thread nevil amos
Hi I can achieve this using two for loops but it is slow I need to do this on many matrices with tens of millions of rows of x,y,z and k What is a faster method to achieve this, I cannot use rep as j changes in each row of the new matrix ### M<-matrix(

Re: [R] Mapping of countries

2020-03-31 Thread ani jaya
Maybe simply add: points(station$Lon, station$Lat, col="red", pch=16, label="Your Country") text(station$Lon, station$Lat,"Your Country", col="black", pos=3, cex=1) station$Lon and Lat in your coordinate position. Regards, Ani On Tue, Mar 31, 2020 at 10:58 PM george brida wrote: > > Dea

[R] Problems using predict with GEE

2020-03-31 Thread Sorkin, John
I am running gee with a an offset followed by predict to get predicted values. The GEE analysis runs without error. When I run the predict function, I get the following error message: Error in seq_len(p) : argument must be coercible to non-negative integer In addition: Warning messages: 1: In pr

Re: [R] How to match strings in two files and replace strings?

2020-03-31 Thread Jim Lemon
Nice improvement. Jim On Wed, Apr 1, 2020 at 3:18 AM Rasmus Liland wrote: > > On 2020-03-30 21:43 -0500, Ana Marija wrote: > > I did run your workflow and this is what I got: > > > > > newout<-merge(output11.frq,marker_info[,c("V5","match_col")],by="match_col") > > Error in `[.data.frame`(marker

Re: [R] Mapping of countries

2020-03-31 Thread David Winsemius
On 3/31/20 6:49 AM, george brida wrote: Dear Jim, Is it possible to add also a title to this map? Many thanks When I look at theĀ  ?map help page, I see all these questions answered in the Examples section. -- David On Tue, Mar 31, 2020 at 2:29 PM george brida wrote: Dear Jim,

Re: [R] Mapping of countries

2020-03-31 Thread Rasmus Liland
On 2020-03-31 03:38 +0200, george brida wrote: > i would like to plot the maps of the Gulf Cooperation Council (GCC) > countries (KSA, Qatar, Bahrain, Kuwait, UAE and Oman) with these > constraints: i/ KSA , Qatar and Bahrain have the same face color , ii/ > Kuweit and UAE with the same face color

Re: [R] How to match strings in two files and replace strings?

2020-03-31 Thread Rasmus Liland
On 2020-03-30 21:43 -0500, Ana Marija wrote: > I did run your workflow and this is what I got: > > > newout<-merge(output11.frq,marker_info[,c("V5","match_col")],by="match_col") > Error in `[.data.frame`(marker_info, , c("V5", "match_col")) : > undefined columns selected > > this is how marker-

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread William Michels via R-help
Hi Ivan, Like Ivan Krylov, I'm not aware of circumstances for simple dataframes where ncol(DF) does not equal length(DF). As I understand it, using ncol() versus length() is important when you're examining an object returned from a function like sapply(), since sapply() will simplify one-column d

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Ivan Calandra
Thanks Matthias for the details! Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0) 2631 9772-243 https://www.researchgate.net/pro

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Prof. Dr. Matthias Kohl
should have added: dim(x)[2L] -> length(x) Am 31.03.20 um 16:21 schrieb Prof. Dr. Matthias Kohl: Dear Ivan, if I enter ncol in the console, I get function (x) dim(x)[2L] indicating that function dim is called. Function dim has a method for data.frame; see methods("dim"). The dim-method f

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Prof. Dr. Matthias Kohl
Dear Ivan, if I enter ncol in the console, I get function (x) dim(x)[2L] indicating that function dim is called. Function dim has a method for data.frame; see methods("dim"). The dim-method for data.frame is dim.data.frame function (x) c(.row_names_info(x, 2L), length(x)) Hence, it cal

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Ivan Calandra
Thanks Ivan for the answer. So it confirms my first thought that these two functions are equivalent when applied to a "simple" data.frame. The reason I was asking is because I have gotten used to use length() in my scripts. It works perfectly and I understand it easily. But to be honest, ncol() i

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Ivan Krylov
On Tue, 31 Mar 2020 14:47:54 +0200 Ivan Calandra wrote: > On a simple data.frame (i.e. each element is a vector), ncol() and > length() will give the same result. > Are they just equivalent on such objects, or are they differences in > some cases? I am not aware of any exceptions to ncol(datafr

Re: [R] Mapping of countries

2020-03-31 Thread george brida
Dear Jim, Is it possible to add also a title to this map? Many thanks On Tue, Mar 31, 2020 at 2:29 PM george brida wrote: > Dear Jim, > > Thank you very much. I obtained now the required map. I would like to know > how to add the names of the countries. > > Best > George > > On Tue, Mar 31,

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Ivan Calandra
That's exactly why I was asking if it really is equivalent and if there are issues using one function or the other -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 5

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Eric Berger
Yes it does because length(list) gives you the number of elements of the list. And in the case of a data frame object that is the number of columns, or ncol(). On Tue, Mar 31, 2020 at 4:37 PM Ivan Calandra wrote: > Thanks Eric, > > I know that, but that doesn't really answer my question, does it

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Ivan Calandra
Thanks Eric, I know that, but that doesn't really answer my question, does it? Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrepos 56567 Neuwied, Germany +49 (0)

Re: [R] ncol() vs. length() on data.frames

2020-03-31 Thread Eric Berger
A data frame is a special case of a list. It is a list of its columns. > is.list( your_data_frame ) # TRUE On Tue, Mar 31, 2020 at 4:04 PM Ivan Calandra wrote: > Dear useRs, > > I have a very simple question: > On a simple data.frame (i.e. each element is a vector), ncol() and > length() will

[R] ncol() vs. length() on data.frames

2020-03-31 Thread Ivan Calandra
Dear useRs, I have a very simple question: On a simple data.frame (i.e. each element is a vector), ncol() and length() will give the same result. Are they just equivalent on such objects, or are they differences in some cases? Is one of them to be preferred for whatever reason? Thanks you, Ivan

Re: [R] Mapping of countries

2020-03-31 Thread george brida
Dear Gunter, It is noted. Thanks Best On Tue, Mar 31, 2020 at 6:04 AM Bert Gunter wrote: > Probably better posted to the r-sig-geo list, where you are more > likely to find the relevant expertise. > > Perhaps see also https://cran.r-project.org/web/views/Spatial.html, > depending on what you p

Re: [R] Mapping of countries

2020-03-31 Thread george brida
Dear Jim, Thank you very much. I obtained now the required map. I would like to know how to add the names of the countries. Best George On Tue, Mar 31, 2020 at 10:10 AM Jim Lemon wrote: > Hi George, > Try this: > > library(maps) > map("world",xlim=c(34.353,60.369),ylim=c(16.7,32.193), > regio

Re: [R] Mapping of countries

2020-03-31 Thread Erin Hodgess
That would have been my code too! On Tue, Mar 31, 2020 at 2:10 AM Jim Lemon wrote: > Hi George, > Try this: > > library(maps) > map("world",xlim=c(34.353,60.369),ylim=c(16.7,32.193), > regions="Saudi Arabia",col="yellow",fill=TRUE) > map("world",regions="Bahrain",col="yellow",fill=TRUE,add=TRU

Re: [R] Mapping of countries

2020-03-31 Thread george brida
Hi Erin, Thanks for the reply. I would like to have just those countries on the map. Best George On Tue, Mar 31, 2020 at 5:02 AM Erin Hodgess wrote: > Hello George! > > Do you mean to have a map of the world with these countries filled in, or > to have just those countries on the map, please?

Re: [R] Mapping of countries

2020-03-31 Thread Jim Lemon
Hi George, Try this: library(maps) map("world",xlim=c(34.353,60.369),ylim=c(16.7,32.193), regions="Saudi Arabia",col="yellow",fill=TRUE) map("world",regions="Bahrain",col="yellow",fill=TRUE,add=TRUE) map("world",regions="Kuwait",col="lightblue",fill=TRUE,add=TRUE) map("world",regions="Qatar",col=