[R] Unusual behavior in e1071?
Hello - I have noticed that when I run svm() the order of my data matters. If the first case in the data frame has y=+1 I get the expected decision rule that says to classify as +1 if f(x)>0. However, if the first case in the data frame has y=-1 then apparently the decision rule being used says to classify as +1 if f(x)<0, and in this case all the coefficients are negative of their values compared to the first case. So the two classification rules are equivalent, but is a user really supposed to know the difference? It is likely they would assume the decision rule is always to classify as +1 if f(x)>0. Does anyone think the behavior I have noticed is as intended, or is otherwise benign? Thank you, Daniel Jeske Professor Department of Statistics University of California - Riverside [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] clip a raster according to a shape file in R.
I have a grid data which has values of a variable (e.g: Temperature). My data has 6069 data points where each data point refers to different latitude and longitude. I want to transform this data to a raster file so that I can clip it according to a shapefile that has much smaller boundaries than the raster ( actually the shapefile basins fall inside the much larger raster file which covers the whole USA). Can I do it by R? I know that this can be done by ArcGIS but I want to do it with R. Please help me. TIA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice xyplot
Thanks all for the clarification! From: Jeff Newmiller To: r-help@r-project.org; Bert Gunter ; array chip Cc: "r-help@r-project.org" Sent: Monday, May 1, 2017 10:53 AM Subject: Re: [R] Lattice xyplot It is not a question of whether lattice "understands" the unsorted data... imagine trying to plot 4 points to form a square instead of a trend line... you would NOT want lattice to sort those points for you. That lattice leaves your data alone gives you more flexibility, even while it adds work for certain applications. -- Sent from my phone. Please excuse my brevity. On May 1, 2017 7:34:09 AM PDT, Bert Gunter wrote: >Yes. type = "l" connects the points in the order given in the data, so >if the x's are not already ordered, the plots will be different after >ordering the x's. > >e.g. > >> x <- c(3,1,2,4,6,5) >> y <- 11:16 >> xyplot(y~x. type = "l") > > >As for why ... that's just the way it was designed. You can always >order the data first, if you don't want this default. > >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 Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help > wrote: >> Dear all, I am new to lattice, so would appreciate anyone's help on >the questions below. I am using xyplot to plot some trend in my >dataset. Using the example dataset attached, I am trying to plot >variable "y" over variable "time" for each subject "id": >> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) >> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", >"l"), xlab = "Time", ylab = "Y") >> >> It appears that it just worked fine. But if I sort the "dat" first, >the plot will look somewhat different! >> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, >groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = >"Y") >> Why is that? Do you need to sort the data first before using xyplot? >Why xyplot can not understand the dataset unless it is sorted first? >> Thanks, >> John >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to assign a value to a specific position of a list
The only thing "compelling" about your example is that you have the pre-conceived (wrong) notion that you have to store your objects under separate names in your global environment. That is not only wrong, it handicaps you for future unified processing of these data. I see a lot of constructs in this code that I would change if there was a reproducible example here... but just reading code out of context all I feel like doing is replacing your uses of assign. EEM <- list() for (i in dir()) { EEM[[ i ]] <- list() fn <- list.files(path = i, pattern = "ASC") tr <- sort(as.numeric(unique(unlist(lapply(strsplit(fn, "-"),"[[", 2) for (j in 1:length(tr)) { fn_tr <- list.files(path = i, pattern = paste(i, tr[j], "...ASC", sep="-")) EEM_tmp <- matrix(NA,ncol = length(fn_tr),nrow = 371) for (k in 1:length(fn_tr)) { data_tmp <- read.csv(paste(i,fn_tr[k],sep="/"), header = FALSE) if (dim(data_tmp)[1] != 371) next EEM_tmp[,k] <- data_tmp[,2] } EEM[[ i ]][[ j ]] <- EEM_tmp } } On Tue, 2 May 2017, Jinsong Zhao wrote: Thank you very much, and your reply is helpful. I don't like assign, and even don't use parse in my previous codes. However, in the case I encountered, assign and parse may be the right tools. Here is the code I used: # in the workspace, there are tens directory. # In each directory, there are lots of *.ASC file, # with second column is the data. # Each *.ASC file has a name with pattern i-tr-??.ASC. # i is the directory name, tr is a group name, and ?? are the index. # I have to collect all tr-?? into a matrix, # and put all i-tr-?? into a list EEM_i. for (i in dir()) { assign(paste("EEM_",i,sep=""), list()) fn <- list.files(path = i, pattern = "ASC") tr <- sort(as.numeric(unique(unlist(lapply(strsplit(fn, "-"),"[[", 2) for (j in 1:length(tr)) { fn_tr <- list.files(path = i, pattern = paste(i, tr[j], "...ASC", sep="-")) EEM_tmp <- matrix(NA,ncol = length(fn_tr),nrow = 371) for (k in 1:length(fn_tr)) { data_tmp <- read.csv(paste(i,fn_tr[k],sep="/"), header = FALSE) if (dim(data_tmp)[1] != 371) next EEM_tmp[,k] <- data_tmp[,2] } eval(parse(text=paste("EEM_",i,"[[",j,"]]<-","EEM_tmp", sep=""))) } } Any alternatives or improvements? Thanks a lot. Best, Jinsong On 2017/4/30 23:48, peter dalgaard wrote: assign(paste("list_", i, "[[1]]", sep = ""), 5) creates a new variable with a funny name. You'd have to parse() and eval() to make that work, something like eval(parse(text=paste("list_",i,"[[1]]<-",5, sep=""))) However, --- fortunes::fortune("parse") If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) --- It is much easier to handle this using a data structure containing a list of lists: l <- rep(list(list()), 10) for ( i in 1:10 ) l[[i]][[1]] <- 5 On 30 Apr 2017, at 17:17 , Jinsong Zhao wrote: Hi there, I have a problem with assign(). Here is the demo code: for (i in 1:10) { # create a list with variable name as list_1, list_2, ..., etc. assign(paste("list_", i, sep = ""), list()) # I hope to assign 5 to list_?[[1]], but I don't know how to code it. # list_1[[1]] <- 5 # works, however assign(paste("list_", i, "[[1]]", sep = "", 5) # does not work } How to do? Is there any alternatives? Many thanks! Best, Jinsong __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Example of the use of the "crt" graphical parameter?
Bendy like spaghetti :-) Thanks, Jim. I wasn't aware of plotrix, and it does seem to be a cornucopia of useful, graphical stuff. In this case, my quest for rotating characters stemmed from what you might call a PHB request that I was eventually able to work around. I posed my original question here just out of curiosity (and frustration, I guess). -- Mike On Mon, May 1, 2017 at 5:23 PM, Jim Lemon wrote: > Hi Michael, > The arctext function (plotrix) does something similar, and the code > could be modified to do what you request. If you do want a working > function, it wouldn't be too hard to program. > > Jim > > > On Tue, May 2, 2017 at 6:57 AM, Michael Hannon > wrote: >> Hi, folks. This is an issue that we've defined away, but I recently >> thought it would be useful to rotate characters in some marginal text >> in a base-R plot. I made a few stabs on using the "crt" parameter but >> was unsuccessful. >> >> I'm deliberately omitting details of my attempts, as I want just to >> focus on the following: if you know of any working example of the use >> of that parameter. will you please send me a link to it? Thanks. >> >> (Note that there are *many* links to Cathode Ray Tubes,) >> >> -- Mike >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [FORGED] Re: Example of the use of the "crt" graphical parameter?
Hmm. Thanks, Paul. That would explain the dearth of examples. -- Mike On Mon, May 1, 2017 at 4:42 PM, Paul Murrell wrote: > Hi > > I do not recall ever using crt. A grep of the source code suggests that no > user-level functions ever refer to it either. In other words, it appears to > be basically unimplemented. > > Specifically with regard to text in the margins of a base plot, in addition > to every function ignoring crt, only the text() function listens to srt (and > that draws in the plot region, not the margins); mtext() (for margin text) > only listens to las, so can only do horizontal or vertical. > > Paul > > > On 02/05/17 09:47, Michael Hannon wrote: >> >> Thanks, Bert. I *did* mean crt, and I did read (and re-read) the man >> page. What I'm lacking, and the only thing I'm asking for, is a >> working example of the use of that parameter. >> >> -- Mike >> >> >> On Mon, May 1, 2017 at 2:08 PM, Bert Gunter >> wrote: >>> >>> Hard to know what you want or did without code. >>> >>> But, a guess: did you want the "srt" parameter and not "crt"? >>> >>> Of course, it's always useful to read the man page, in this case for >>> ?par, where it says: >>> >>> (for crt): "A numerical value specifying (in degrees) how **single >>> characters** should be rotated. It is unwise to expect values other >>> than multiples of 90 to work. Compare with srt which does string >>> rotation." [note: "string" = several characters = text] >>> >>> >>> 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, May 1, 2017 at 1:57 PM, Michael Hannon >>> wrote: Hi, folks. This is an issue that we've defined away, but I recently thought it would be useful to rotate characters in some marginal text in a base-R plot. I made a few stabs on using the "crt" parameter but was unsuccessful. I'm deliberately omitting details of my attempts, as I want just to focus on the following: if you know of any working example of the use of that parameter. will you please send me a link to it? Thanks. (Note that there are *many* links to Cathode Ray Tubes,) -- Mike __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. >> >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- > Dr Paul Murrell > Department of Statistics > The University of Auckland > Private Bag 92019 > Auckland > New Zealand > 64 9 3737599 x85392 > p...@stat.auckland.ac.nz > http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to assign a value to a specific position of a list
Thank you very much, and your reply is helpful. I don't like assign, and even don't use parse in my previous codes. However, in the case I encountered, assign and parse may be the right tools. Here is the code I used: # in the workspace, there are tens directory. # In each directory, there are lots of *.ASC file, # with second column is the data. # Each *.ASC file has a name with pattern i-tr-??.ASC. # i is the directory name, tr is a group name, and ?? are the index. # I have to collect all tr-?? into a matrix, # and put all i-tr-?? into a list EEM_i. for (i in dir()) { assign(paste("EEM_",i,sep=""), list()) fn <- list.files(path = i, pattern = "ASC") tr <- sort(as.numeric(unique(unlist(lapply(strsplit(fn, "-"),"[[", 2) for (j in 1:length(tr)) { fn_tr <- list.files(path = i, pattern = paste(i, tr[j], "...ASC", sep="-")) EEM_tmp <- matrix(NA,ncol = length(fn_tr),nrow = 371) for (k in 1:length(fn_tr)) { data_tmp <- read.csv(paste(i,fn_tr[k],sep="/"), header = FALSE) if (dim(data_tmp)[1] != 371) next EEM_tmp[,k] <- data_tmp[,2] } eval(parse(text=paste("EEM_",i,"[[",j,"]]<-","EEM_tmp", sep=""))) } } Any alternatives or improvements? Thanks a lot. Best, Jinsong On 2017/4/30 23:48, peter dalgaard wrote: assign(paste("list_", i, "[[1]]", sep = ""), 5) creates a new variable with a funny name. You'd have to parse() and eval() to make that work, something like eval(parse(text=paste("list_",i,"[[1]]<-",5, sep=""))) However, --- fortunes::fortune("parse") If the answer is parse() you should usually rethink the question. -- Thomas Lumley R-help (February 2005) --- It is much easier to handle this using a data structure containing a list of lists: l <- rep(list(list()), 10) for ( i in 1:10 ) l[[i]][[1]] <- 5 On 30 Apr 2017, at 17:17 , Jinsong Zhao wrote: Hi there, I have a problem with assign(). Here is the demo code: for (i in 1:10) { # create a list with variable name as list_1, list_2, ..., etc. assign(paste("list_", i, sep = ""), list()) # I hope to assign 5 to list_?[[1]], but I don't know how to code it. # list_1[[1]] <- 5 # works, however assign(paste("list_", i, "[[1]]", sep = "", 5) # does not work } How to do? Is there any alternatives? Many thanks! Best, Jinsong __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Example of the use of the "crt" graphical parameter?
Hi Michael, The arctext function (plotrix) does something similar, and the code could be modified to do what you request. If you do want a working function, it wouldn't be too hard to program. Jim On Tue, May 2, 2017 at 6:57 AM, Michael Hannon wrote: > Hi, folks. This is an issue that we've defined away, but I recently > thought it would be useful to rotate characters in some marginal text > in a base-R plot. I made a few stabs on using the "crt" parameter but > was unsuccessful. > > I'm deliberately omitting details of my attempts, as I want just to > focus on the following: if you know of any working example of the use > of that parameter. will you please send me a link to it? Thanks. > > (Note that there are *many* links to Cathode Ray Tubes,) > > -- Mike > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [FORGED] Re: Example of the use of the "crt" graphical parameter?
Hi I do not recall ever using crt. A grep of the source code suggests that no user-level functions ever refer to it either. In other words, it appears to be basically unimplemented. Specifically with regard to text in the margins of a base plot, in addition to every function ignoring crt, only the text() function listens to srt (and that draws in the plot region, not the margins); mtext() (for margin text) only listens to las, so can only do horizontal or vertical. Paul On 02/05/17 09:47, Michael Hannon wrote: Thanks, Bert. I *did* mean crt, and I did read (and re-read) the man page. What I'm lacking, and the only thing I'm asking for, is a working example of the use of that parameter. -- Mike On Mon, May 1, 2017 at 2:08 PM, Bert Gunter wrote: Hard to know what you want or did without code. But, a guess: did you want the "srt" parameter and not "crt"? Of course, it's always useful to read the man page, in this case for ?par, where it says: (for crt): "A numerical value specifying (in degrees) how **single characters** should be rotated. It is unwise to expect values other than multiples of 90 to work. Compare with srt which does string rotation." [note: "string" = several characters = text] 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, May 1, 2017 at 1:57 PM, Michael Hannon wrote: Hi, folks. This is an issue that we've defined away, but I recently thought it would be useful to rotate characters in some marginal text in a base-R plot. I made a few stabs on using the "crt" parameter but was unsuccessful. I'm deliberately omitting details of my attempts, as I want just to focus on the following: if you know of any working example of the use of that parameter. will you please send me a link to it? Thanks. (Note that there are *many* links to Cathode Ray Tubes,) -- Mike __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 p...@stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Example of the use of the "crt" graphical parameter?
Perhaps R does what S+ does with par("crt"). S+'s help(par) says: crt=x character rotation in degrees measured counterclockwise from horizontal. When srt is set, crt is automatically set to the same value, unless crt appears later in the command than srt. Many graphics devices ignore crt and use only srt, so setting them to different values has no effect on those devices. A few graphics devices cannot rotate text, or can rotate it only at multiples of 90 degrees. "Many graphics devices" means "most modern graphics devices", where "modern" means post 1990 or so, when pen plotters went out of fashion. Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, May 1, 2017 at 3:20 PM, Bert Gunter wrote: > FWIW: > > "srt = 90" should rotate the whole string "aa" 90 degrees in a > call to text(), and it does. > > I interpret "crt =90" to rotate the individual letters of "aa" 90 > degrees, but it does not on my graphic device, RStudioGD. It probably > works on some other devices, but I don't know which ones. > > HTH. > > 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, May 1, 2017 at 2:08 PM, Bert Gunter > wrote: > > Hard to know what you want or did without code. > > > > But, a guess: did you want the "srt" parameter and not "crt"? > > > > Of course, it's always useful to read the man page, in this case for > > ?par, where it says: > > > > (for crt): "A numerical value specifying (in degrees) how **single > > characters** should be rotated. It is unwise to expect values other > > than multiples of 90 to work. Compare with srt which does string > > rotation." [note: "string" = several characters = text] > > > > > > 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, May 1, 2017 at 1:57 PM, Michael Hannon > > wrote: > >> Hi, folks. This is an issue that we've defined away, but I recently > >> thought it would be useful to rotate characters in some marginal text > >> in a base-R plot. I made a few stabs on using the "crt" parameter but > >> was unsuccessful. > >> > >> I'm deliberately omitting details of my attempts, as I want just to > >> focus on the following: if you know of any working example of the use > >> of that parameter. will you please send me a link to it? Thanks. > >> > >> (Note that there are *many* links to Cathode Ray Tubes,) > >> > >> -- Mike > >> > >> __ > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> https://stat.ethz.ch/mailman/listinfo/r-help > >> PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > >> and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Example of the use of the "crt" graphical parameter?
FWIW: "srt = 90" should rotate the whole string "aa" 90 degrees in a call to text(), and it does. I interpret "crt =90" to rotate the individual letters of "aa" 90 degrees, but it does not on my graphic device, RStudioGD. It probably works on some other devices, but I don't know which ones. HTH. 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, May 1, 2017 at 2:08 PM, Bert Gunter wrote: > Hard to know what you want or did without code. > > But, a guess: did you want the "srt" parameter and not "crt"? > > Of course, it's always useful to read the man page, in this case for > ?par, where it says: > > (for crt): "A numerical value specifying (in degrees) how **single > characters** should be rotated. It is unwise to expect values other > than multiples of 90 to work. Compare with srt which does string > rotation." [note: "string" = several characters = text] > > > 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, May 1, 2017 at 1:57 PM, Michael Hannon > wrote: >> Hi, folks. This is an issue that we've defined away, but I recently >> thought it would be useful to rotate characters in some marginal text >> in a base-R plot. I made a few stabs on using the "crt" parameter but >> was unsuccessful. >> >> I'm deliberately omitting details of my attempts, as I want just to >> focus on the following: if you know of any working example of the use >> of that parameter. will you please send me a link to it? Thanks. >> >> (Note that there are *many* links to Cathode Ray Tubes,) >> >> -- Mike >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Example of the use of the "crt" graphical parameter?
Thanks, Bert. I *did* mean crt, and I did read (and re-read) the man page. What I'm lacking, and the only thing I'm asking for, is a working example of the use of that parameter. -- Mike On Mon, May 1, 2017 at 2:08 PM, Bert Gunter wrote: > Hard to know what you want or did without code. > > But, a guess: did you want the "srt" parameter and not "crt"? > > Of course, it's always useful to read the man page, in this case for > ?par, where it says: > > (for crt): "A numerical value specifying (in degrees) how **single > characters** should be rotated. It is unwise to expect values other > than multiples of 90 to work. Compare with srt which does string > rotation." [note: "string" = several characters = text] > > > 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, May 1, 2017 at 1:57 PM, Michael Hannon > wrote: >> Hi, folks. This is an issue that we've defined away, but I recently >> thought it would be useful to rotate characters in some marginal text >> in a base-R plot. I made a few stabs on using the "crt" parameter but >> was unsuccessful. >> >> I'm deliberately omitting details of my attempts, as I want just to >> focus on the following: if you know of any working example of the use >> of that parameter. will you please send me a link to it? Thanks. >> >> (Note that there are *many* links to Cathode Ray Tubes,) >> >> -- Mike >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Example of the use of the "crt" graphical parameter?
Hard to know what you want or did without code. But, a guess: did you want the "srt" parameter and not "crt"? Of course, it's always useful to read the man page, in this case for ?par, where it says: (for crt): "A numerical value specifying (in degrees) how **single characters** should be rotated. It is unwise to expect values other than multiples of 90 to work. Compare with srt which does string rotation." [note: "string" = several characters = text] 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, May 1, 2017 at 1:57 PM, Michael Hannon wrote: > Hi, folks. This is an issue that we've defined away, but I recently > thought it would be useful to rotate characters in some marginal text > in a base-R plot. I made a few stabs on using the "crt" parameter but > was unsuccessful. > > I'm deliberately omitting details of my attempts, as I want just to > focus on the following: if you know of any working example of the use > of that parameter. will you please send me a link to it? Thanks. > > (Note that there are *many* links to Cathode Ray Tubes,) > > -- Mike > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Example of the use of the "crt" graphical parameter?
Hi, folks. This is an issue that we've defined away, but I recently thought it would be useful to rotate characters in some marginal text in a base-R plot. I made a few stabs on using the "crt" parameter but was unsuccessful. I'm deliberately omitting details of my attempts, as I want just to focus on the following: if you know of any working example of the use of that parameter. will you please send me a link to it? Thanks. (Note that there are *many* links to Cathode Ray Tubes,) -- Mike __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice xyplot
> On 1 May 2017, at 17:59 , Bert Gunter wrote: > > (Too trivial for the list) ...so you decided to include us only once? >;-) -pd > > I debated saying something similar but decided not to, as polygons can > be drawn e.g. via panel.polygon. > > Cheers, > Bert > > > > > On Mon, May 1, 2017 at 8:25 AM, Jeff Newmiller > wrote: >> It is not a question of whether lattice "understands" the unsorted data... >> imagine trying to plot 4 points to form a square instead of a trend line... >> you would NOT want lattice to sort those points for you. That lattice leaves >> your data alone gives you more flexibility, even while it adds work for >> certain applications. >> >> -- >> Sent from my phone. Please excuse my brevity. >> >> On May 1, 2017 7:34:09 AM PDT, Bert Gunter wrote: >>> Yes. type = "l" connects the points in the order given in the data, so >>> if the x's are not already ordered, the plots will be different after >>> ordering the x's. >>> >>> e.g. >>> x <- c(3,1,2,4,6,5) y <- 11:16 xyplot(y~x. type = "l") >>> >>> >>> As for why ... that's just the way it was designed. You can always >>> order the data first, if you don't want this default. >>> >>> 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 Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help >>> wrote: Dear all, I am new to lattice, so would appreciate anyone's help on >>> the questions below. I am using xyplot to plot some trend in my >>> dataset. Using the example dataset attached, I am trying to plot >>> variable "y" over variable "time" for each subject "id": dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", >>> "l"), xlab = "Time", ylab = "Y") It appears that it just worked fine. But if I sort the "dat" first, >>> the plot will look somewhat different! dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, >>> groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = >>> "Y") Why is that? Do you need to sort the data first before using xyplot? >>> Why xyplot can not understand the dataset unless it is sorted first? Thanks, John __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finding nrows with specefic values&converting a matrix into a table
Copy your queries to the help list. Do not use html (google "send plain text email using hotmail"). Copy your actual code creating the object and writing with any warning or error message into your email. Do not just give us a description of what you did. Include information about the object you are trying to save using class() and dim(). Without that information, it is not possible to help you. Based on your email, we don't know if the problem is with R or with Excel. Different versions of Excel have different limits for the number of rows and columns. Why would you try both write.csv() and write.csv2() since they are the same except for how to represent decimal numbers? Have you tried using read.csv() to read the .csv file you created to see if it is the same size as the one you wrote? Have you opened the .csv file in a text editor to see if it is properly formatted and contains the number of records you think it does? David C From: abo dalash [mailto:abo_d...@hotmail.com] Sent: Sunday, April 30, 2017 7:20 PM To: David L Carlson Subject: Re: [R] Finding nrows with specefic values&converting a matrix into a table I have been trying to export the file for about 5 hours now without a result! I have read what is in the manual but did not find any formats except write.table(),write.csv(), write.csv2(). No one works. I have also highlighted all table in R and copied it into an excel file but this has just copied the first 200 rows and I have about 15000 rows. All my tries end with exporting all columns in a single column in the new file without separation. From: David L Carlson Sent: 01 May 2017 02:54 AM To: abo dalash; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table No. You are not using the correct command. Time to read the manual: ?write.table You will find the answer to your question by looking at the alternate forms of write.*(). David L. Carlson Department of Anthropology Texas A&M University From: abo dalash [mailto:abo_d...@hotmail.com] Sent: Sunday, April 30, 2017 2:36 PM To: David L Carlson ; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table I'm trying to write the table I have created from the matrix using write.table(mytable, file= "mytable.txt"). I have imported this txt. file into an Excel sheet but all data have been typed in one column (Var1,Var2,&Freq.) and I want to see each vector in one column. Have I used the correct syntax? Regards From: David L Carlson Sent: 30 April 2017 07:33 PM To: abo dalash; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table Show us the code you used. Don't just tell us what you did. It is likely that something you did after creating the matrix converted it to a data frame. Copy and paste your code to your emails. > str(mydf) 'data.frame': 3 obs. of 3 variables: $ x: int 0 NA NA $ y: int 5 0 NA $ z: int 67 23 0 > data.frame(as.table(as.matrix(mydf))) Var1 Var2 Freq 1 x x 0 2 y x NA 3 z x NA 4 x y 5 5 y y 0 6 z y NA David C From: abo dalash [mailto:abo_d...@hotmail.com] Sent: Sunday, April 30, 2017 11:13 AM To: David L Carlson Subject: Re: [R] Finding nrows with specefic values&converting a matrix into a table str(mymatrix) The Structure shows that this is a 'data.frame'? of 120 obs. and 120 variables of numeric type. R deals with my matrix as a data frame although I used the function matrix() to produce this matrix which is not clear to me why. As this is already a data.frame, this may explains why R returns me the same matrix. What do you recommend now? Many thanks From: David L Carlson Sent: 30 April 2017 06:47 PM To: abo dalash; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table You did not give me any information about about your data using str() or class() so I'll guess that you have a matrix, e.g.: > class(moredata) [1] "matrix" > as.data.frame.table(moredata) Var1 Var2 Freq 1 x x 0 2 y x NA 3 z x NA 4 x y 5 5 y y 0 6 z y NA 7 x z 67 8 y z 23 9 z z 0 David C From: abo dalash [mailto:abo_d...@hotmail.com] Sent: Sunday, April 30, 2017 10:09 AM To: David L Carlson ; r-help@R-project.org Subject: Re: [R] Finding nrows with specefic values&converting a matrix into a table Dear David .., Many thanks for this detailed answer. Your guidance reg. the first task has resolved my issue and I have understood now how to perform this type of analysis. I have saved your learning tips in my script. Reg. the Matrix-table conversion, could you please clarify this more?. I applied the function as.data.frame but
Re: [R] how to assign a value to a specific position of a list
It's not clear what you're trying to do. However, to "assign a value to a specific position of a list", this example should show you how. lst <- vector('list', 10) ## see the help page for list names(lst) <- paste0('list.',1:10) ## to assign 'a' to position 3: pos <- 3 lst[[pos]] <- 'a' I completely agree with Jeff Newmiller's recommendation to avoid using assign. It's probably the wrong tool for what you're trying to do (whatever that is). (and note that I have borrowed Jeff's name "lst" for the list with 10 elements [not variables] whose names are "list_1" "list_2" etc.) (and I refuse to use "_" in R object names, but that's a personal preference) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 4/30/17, 8:17 AM, "R-help on behalf of Jinsong Zhao" wrote: Hi there, I have a problem with assign(). Here is the demo code: for (i in 1:10) { # create a list with variable name as list_1, list_2, ..., etc. assign(paste("list_", i, sep = ""), list()) # I hope to assign 5 to list_?[[1]], but I don't know how to code it. # list_1[[1]] <- 5 # works, however assign(paste("list_", i, "[[1]]", sep = "", 5) # does not work } How to do? Is there any alternatives? Many thanks! Best, Jinsong __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] survival package can't find Ccoxfit6
Thank you everyone for all your help. Dr. Therneau and I had some offline email exchange and he offered to add resid= and concordance= options which will reduce the computational overhead in resampling scenarios such as mine. It will also avoid having to access unexported internals. Thanks, Venkat -Original Message- From: Duncan Murdoch [mailto:murdoch.dun...@gmail.com] Sent: Friday, April 28, 2017 6:46 PM To: Henric Winell; Therneau, Terry M., Ph.D.; R-help Cc: Seshan, Venkatraman E./Epidemiology-Biostatistics Subject: Re: [R] survival package can't find Ccoxfit6 On 28/04/2017 5:37 PM, Henric Winell wrote: > On 2017-04-26 22:17, Duncan Murdoch wrote: > >> On 26/04/2017 2:51 PM, Therneau, Terry M., Ph.D. wrote: >>> A user contacted me directly about this, I answered with my best >>> understanding of the recent R-help discussion of the issue, and >>> their response to my response shows that I'm not quite right. >>> >>> I am emphatically not an MS Windows user so am asking for help -- >>> which I will cut/paste to this user and to the next dozen who will >>> invariably contact me directly. >>> >>> Thanks, >>>Terry Therneau >>> >>> >>> >>> Forwarded Message >>> Subject: RE: survival package >>> Date: Wed, 26 Apr 2017 18:05:30 + >>> From: sesh...@mskcc.org >>> To: Therneau, Terry M., Ph.D. >>> >>> Thank you for the quick response. The session info command for >>> v3.4.0 does in fact report survival_2.41-3. Furthermore, while both >>> v3.3.1 and v3.40 are on the same computer the library paths do not >>> have any directory in common: >>> .libPaths() >>> [1] "C:/Program Files/R/R-3.4.0/library" >>> >>> and .libPaths() >>> [1] "C:/Program Files/R/R-3.3.1/library" >>> >>> >>> Thanks, >>> Venkat >>> >>> >>> -Original Message- >>> From: Therneau, Terry M., Ph.D. [mailto:thern...@mayo.edu] Sent: >>> Wednesday, April 26, 2017 >>> 1:42 PM >>> To: Seshan, Venkatraman E./Epidemiology-Biostatistics >>> Subject: Re: survival package >>> >>> This has been discussed in R-help by multiple people. You have a >>> pre-3.4 version of the >>> survival package somewhere on your search path, and the method for >>> resolving .C calls has >>> changed. The sessionInfo command should report survival version 2.41-3. >>> >>> Terry T. >>> >>> >>> On 04/26/2017 12:17 PM, sesh...@mskcc.org wrote: Dear Prof. Therneau, I am encountering an error message when I try to use the coxfit6 routine from the survival package under the 3.4.0 version of R. The minimal function and the script are in the attached file. This function worked under earlier versions of R. --- --- - *** ** Works under R-3.3.1 ** *** > source("coxfit6-issue.R") [1] -0.4838181 > sessionInfo() R version 3.3.1 (2016-06-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 7 x64 (build 7601) Service Pack 1 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] survival_2.39-4 loaded via a namespace (and not attached): [1] Matrix_1.2-6splines_3.3.1 grid_3.3.1 lattice_0.20-33 --- --- - *** ** Does not work under R-3.4.0 ** *** > library(survival) > source("coxfit6-issue.R") Error in .Call("Ccoxfit6", as.integer(control$iter.max), stime, as.integer(sstat), : "Ccoxfit6" not available for .Call() for package "survival" >> >> As far as I can see, that line doesn't appear in the current survival >> source code, it's from some earlier version of the package. The >> current one has >> >> coxfit <- .Call(Ccoxfit6, >> as.integer(maxiter), >> stime, >> sstat, >> x[sorted,], >> as.double(offset[sorted]), >> weights, >> newstrat, >> as.integer(method=="efron"), >> as.double(control$eps), >> as.double(control$toler.chol), >> as.vector(init), >> as.integer(1)) # internally rescale >> >> There are several differences, the one leading to the error being the >> change from "Ccoxfit6" in quotes, to Ccoxfit6 not in quotes. That >> corres
Re: [R] cannot load .sav-files in R 3.4.0
did my code work? thanks On Mon, May 1, 2017 at 11:35 AM, wrote: > hi, thanks for the reply! > it always worked until 3.4.0. i got warning but they did not stop R > loading the file ... > > Am 01.05.2017 16:10 schrieb Anthony Damico: > >> hi, i don't think foreign::read.spss or haven::read_spss have ever >> worked with a handful of the ess files, but library(memisc) does. you >> are better off loading ess with library(lodown) because the drudge >> work has already been done-- >> >> library(devtools) >> devtools::install_github("ajdamico/lodown") >> library(lodown) >> ess_cat <- get_catalog( "ess" , output_dir = "C:/My Directory/ESS" >> ) >> >> # which entries do you want? >> head(ess_cat) >> >> # how about wave 7 only >> sub_ess_cat <- subset( ess_cat , wave == 7 ) >> >> # replace the email address with whatever you registered with >> lodown( "ess" , sub_ess_cat , your_email = "em...@address.com" ) >> >> x <- readRDS( "C:/My Directory/ESS/2014/ESS7csCH.rds" ) >> >> # looks good >> head( x ) >> >> On Mon, May 1, 2017 at 6:22 AM, >> wrote: >> >> after updating R from 3.3.3. to 3.4.0 i cannot import spss-data >>> files anymore. for the european social survey >>> (europeansocialsurvey.org [1]) i get this warning: >>> re-encoding from CP1252 >>> Fehler in levels<-(*tmp*, value = if (nl == nL) >>> as.character(labels) else paste0(labels, : >>> factor level [3] is duplicated >>> Zusätzlich: Warnmeldung: >>> In read.spss(file, use.value.labels = use.value.labels, >>> to.data.frame = to.data.frame, : >>> //filepath/ESS7CH.sav: Unrecognized record type 7, subtype 18 >>> encountered in system file >>> >>> using the package foreign does the same. >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help [2] >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html [3] >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> >> >> Links: >> -- >> [1] http://europeansocialsurvey.org >> [2] https://stat.ethz.ch/mailman/listinfo/r-help >> [3] http://www.R-project.org/posting-guide.html >> > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice xyplot
(Too trivial for the list) I debated saying something similar but decided not to, as polygons can be drawn e.g. via panel.polygon. Cheers, Bert On Mon, May 1, 2017 at 8:25 AM, Jeff Newmiller wrote: > It is not a question of whether lattice "understands" the unsorted data... > imagine trying to plot 4 points to form a square instead of a trend line... > you would NOT want lattice to sort those points for you. That lattice leaves > your data alone gives you more flexibility, even while it adds work for > certain applications. > > -- > Sent from my phone. Please excuse my brevity. > > On May 1, 2017 7:34:09 AM PDT, Bert Gunter wrote: >>Yes. type = "l" connects the points in the order given in the data, so >>if the x's are not already ordered, the plots will be different after >>ordering the x's. >> >>e.g. >> >>> x <- c(3,1,2,4,6,5) >>> y <- 11:16 >>> xyplot(y~x. type = "l") >> >> >>As for why ... that's just the way it was designed. You can always >>order the data first, if you don't want this default. >> >>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 Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help >> wrote: >>> Dear all, I am new to lattice, so would appreciate anyone's help on >>the questions below. I am using xyplot to plot some trend in my >>dataset. Using the example dataset attached, I am trying to plot >>variable "y" over variable "time" for each subject "id": >>> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) >>> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", >>"l"), xlab = "Time", ylab = "Y") >>> >>> It appears that it just worked fine. But if I sort the "dat" first, >>the plot will look somewhat different! >>> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, >>groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = >>"Y") >>> Why is that? Do you need to sort the data first before using xyplot? >>Why xyplot can not understand the dataset unless it is sorted first? >>> Thanks, >>> John >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >> >>__ >>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>https://stat.ethz.ch/mailman/listinfo/r-help >>PLEASE do read the posting guide >>http://www.R-project.org/posting-guide.html >>and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice xyplot
It is not a question of whether lattice "understands" the unsorted data... imagine trying to plot 4 points to form a square instead of a trend line... you would NOT want lattice to sort those points for you. That lattice leaves your data alone gives you more flexibility, even while it adds work for certain applications. -- Sent from my phone. Please excuse my brevity. On May 1, 2017 7:34:09 AM PDT, Bert Gunter wrote: >Yes. type = "l" connects the points in the order given in the data, so >if the x's are not already ordered, the plots will be different after >ordering the x's. > >e.g. > >> x <- c(3,1,2,4,6,5) >> y <- 11:16 >> xyplot(y~x. type = "l") > > >As for why ... that's just the way it was designed. You can always >order the data first, if you don't want this default. > >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 Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help > wrote: >> Dear all, I am new to lattice, so would appreciate anyone's help on >the questions below. I am using xyplot to plot some trend in my >dataset. Using the example dataset attached, I am trying to plot >variable "y" over variable "time" for each subject "id": >> dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) >> xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", >"l"), xlab = "Time", ylab = "Y") >> >> It appears that it just worked fine. But if I sort the "dat" first, >the plot will look somewhat different! >> dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, >groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = >"Y") >> Why is that? Do you need to sort the data first before using xyplot? >Why xyplot can not understand the dataset unless it is sorted first? >> Thanks, >> John >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice xyplot
In addition to Berts comments Once you change the order you change the non factored id' ordering. If you make it a factor it may be easier to see what is going on I think I have copied correctly - see the differences # original data xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") # order dat2<-dat[order(dat$id, dat$time),] xyplot(y ~ time, data=dat2, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") # make ID a factor dat3 <- dat1 xyplot(y ~ time, data=dat3, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") # ordered + ID a factor dat4 <- dat3 dat4<-dat[order(dat4$id, dat4$time),] xyplot(y ~ time, data=dat4, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of array chip via R-help Sent: Monday, 1 May 2017 11:07 To: r-help@r-project.org Subject: [R] Lattice xyplot Dear all, I am new to lattice, so would appreciate anyone's help on the questions below. I am using xyplot to plot some trend in my dataset. Using the example dataset attached, I am trying to plot variable "y" over variable "time" for each subject "id": dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") It appears that it just worked fine. But if I sort the "dat" first, the plot will look somewhat different! dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") Why is that? Do you need to sort the data first before using xyplot? Why xyplot can not understand the dataset unless it is sorted first? Thanks, John __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Lattice xyplot
Yes. type = "l" connects the points in the order given in the data, so if the x's are not already ordered, the plots will be different after ordering the x's. e.g. > x <- c(3,1,2,4,6,5) > y <- 11:16 > xyplot(y~x. type = "l") As for why ... that's just the way it was designed. You can always order the data first, if you don't want this default. 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 Sun, Apr 30, 2017 at 6:07 PM, array chip via R-help wrote: > Dear all, I am new to lattice, so would appreciate anyone's help on the > questions below. I am using xyplot to plot some trend in my dataset. Using > the example dataset attached, I am trying to plot variable "y" over variable > "time" for each subject "id": > dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) > xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), > xlab = "Time", ylab = "Y") > > It appears that it just worked fine. But if I sort the "dat" first, the plot > will look somewhat different! > dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, > aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") > Why is that? Do you need to sort the data first before using xyplot? Why > xyplot can not understand the dataset unless it is sorted first? > Thanks, > John > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem loading spss-files
I pasted some of the error/warning message into Google and among other things: http://stackoverflow.com/questions/21228518/what-is-attr-value-labels-when-reading-spss-into-r This might begin to explain what is happening. Is a data.frame created? Rick B. From: R-help on behalf of Siouxsie Sent: Monday, May 01, 2017 6:23 AM To: R help Subject: [R] problem loading spss-files after updating R from 3.3.3. to 3.4.0 i cannot import spss-data files anymore. for the european social survey (europeansocialsurvey.org) i get this warning: re-encoding from CP1252 Fehler in levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : factor level [3] is duplicated Zus�tzlich: Warnmeldung: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame, : //filepath/ESS7CH.sav: Unrecognized record type 7, subtype 18 encountered in system file using the package foreign does the same. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=01%7C01%7Crab45%40pitt.edu%7C8c4c5ed34ae94d3df7d208d4908f3bd2%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=FolAovtD1w5XU%2BBcEDGu7DLbRYGJIcEDWu%2BUCl9j9tA%3D&reserved=0 PLEASE do read the posting guide https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.R-project.org%2Fposting-guide.html&data=01%7C01%7Crab45%40pitt.edu%7C8c4c5ed34ae94d3df7d208d4908f3bd2%7C9ef9f489e0a04eeb87cc3a526112fd0d%7C1&sdata=xNrROh3MnSgpTaKT%2F6vi4ZT0ffXtmh7DbYh0IadrKa0%3D&reserved=0 and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] cannot load .sav-files in R 3.4.0
hi, i don't think foreign::read.spss or haven::read_spss have ever worked with a handful of the ess files, but library(memisc) does. you are better off loading ess with library(lodown) because the drudge work has already been done-- library(devtools) devtools::install_github("ajdamico/lodown") library(lodown) ess_cat <- get_catalog( "ess" , output_dir = "C:/My Directory/ESS" ) # which entries do you want? head(ess_cat) # how about wave 7 only sub_ess_cat <- subset( ess_cat , wave == 7 ) # replace the email address with whatever you registered with lodown( "ess" , sub_ess_cat , your_email = "em...@address.com" ) x <- readRDS( "C:/My Directory/ESS/2014/ESS7csCH.rds" ) # looks good head( x ) On Mon, May 1, 2017 at 6:22 AM, wrote: > after updating R from 3.3.3. to 3.4.0 i cannot import spss-data files > anymore. for the european social survey (europeansocialsurvey.org) i get > this warning: > re-encoding from CP1252 > Fehler in levels<-(*tmp*, value = if (nl == nL) as.character(labels) else > paste0(labels, : > factor level [3] is duplicated > Zusätzlich: Warnmeldung: > In read.spss(file, use.value.labels = use.value.labels, to.data.frame = > to.data.frame, : > //filepath/ESS7CH.sav: Unrecognized record type 7, subtype 18 encountered > in system file > > using the package foreign does the same. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posti > ng-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] cannot load .sav-files in R 3.4.0
after updating R from 3.3.3. to 3.4.0 i cannot import spss-data files anymore. for the european social survey (europeansocialsurvey.org) i get this warning: re-encoding from CP1252 Fehler in levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : factor level [3] is duplicated Zusätzlich: Warnmeldung: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame, : //filepath/ESS7CH.sav: Unrecognized record type 7, subtype 18 encountered in system file using the package foreign does the same. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem loading spss-files
after updating R from 3.3.3. to 3.4.0 i cannot import spss-data files anymore. for the european social survey (europeansocialsurvey.org) i get this warning: re-encoding from CP1252 Fehler in levels<-(*tmp*, value = if (nl == nL) as.character(labels) else paste0(labels, : factor level [3] is duplicated Zusätzlich: Warnmeldung: In read.spss(file, use.value.labels = use.value.labels, to.data.frame = to.data.frame, : //filepath/ESS7CH.sav: Unrecognized record type 7, subtype 18 encountered in system file using the package foreign does the same. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Whitespace
That looks like an error from Stan parsing your stan file, but the code you put in the message doesn't look like Stan code, it looks like R code, so maybe you've tried to parse your R code with Stan There's no mention of stan in the code either, like the rstan package, so somehow you've got a Stan error message from some R code without calling stan... Okay, I'm well confused now... On Mon, May 1, 2017 at 5:57 AM, Miguel Angel Hombrados Herrera wrote: > Hello > > > Ive been working on a stan program in Rstudio. Im kind of new on this, so > probably my question is trivial, However I was not able to find information > about this. > > The error Im getting when I run my stan code is: > > > PARSER EXPECTED: whitespace to end of file. > FOUND AT line 2: > > > The code is: > > iter=500 > alphamcmc=matrix(0,ncol=J,nrow=iter) > betamcmc=NULL > mu_alpha=NULL > sigma_alpha_2=NULL > sigma_y_2=NULL > #set initial values > alphamcmc[1,]=rep(mean(y),J) > betamcmc[1]=70 > mu_alpha[1]=mean(y) > sigma_alpha_2[1]=300 > sigma_y_2[1]=350 > #mcmc iteration > for(m in 2:iter){ > #update alpha vector > for(j in 1:J){ > sj=sum(source==j) > var=1/(sj/sigma_y_2[m-1]+1/sigma_alpha_2[m-1]) > temp=0 > for(i in 1:N){temp=temp+1*(source[i]==j)*(y[i]-betamcmc[m-1]*x[i])} > #sum up (y_i-beta x_i ) for those belonging to group j > mean=var*(temp/sigma_y_2[m-1]+mu_alpha[m-1]/sigma_alpha_2[m-1]) > alphamcmc[m,j]=rnorm(1,mean,sqrt(var)) > } > #update beta > var=sigma_alpha_2[m-1]/(sum(x^2)) > mean=sum(x%*%(y-alphamcmc[m,source])/sum(sum(x^2))) > betamcmc[m]=rnorm(1,mean,sqrt(var)) > #update mu_alpha > #update sigma_alpha_2 > sigma_alpha_2[m]=rinvgamma(1,shape=J/2,rate=sum((alphamcmc[m,] > -mu_alpha[m])^2/2)) > #update sigma_y_2 > sigma_y_2[m]=rinvgamma(1,shape=N/2,rate=sum((y-alphamcmc[m,source]- > betamcmc[m]*x)^2/2)) > } > nburn=200 > apply(alphamcmc[(nburn+1):iter,],2,mean) > apply(betamcmc[(nburn+1):iter],2,mean) > > Ive been searching for wrong spaces or tabulations, but I was not able to > find anything. > > I really would appreciate your help. > Thaknk you. > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Whitespace
Hi Miguel, You don't seem to have defined "J" before line 2. Maybe that is the problem. Jim On Mon, May 1, 2017 at 2:57 PM, Miguel Angel Hombrados Herrera wrote: > Hello > > > Ive been working on a stan program in Rstudio. Im kind of new on this, so > probably my question is trivial, However I was not able to find information > about this. > > The error Im getting when I run my stan code is: > > > PARSER EXPECTED: whitespace to end of file. > FOUND AT line 2: > > > The code is: > > iter=500 > alphamcmc=matrix(0,ncol=J,nrow=iter) > betamcmc=NULL > mu_alpha=NULL > sigma_alpha_2=NULL > sigma_y_2=NULL > #set initial values > alphamcmc[1,]=rep(mean(y),J) > betamcmc[1]=70 > mu_alpha[1]=mean(y) > sigma_alpha_2[1]=300 > sigma_y_2[1]=350 > #mcmc iteration > for(m in 2:iter){ > #update alpha vector > for(j in 1:J){ > sj=sum(source==j) > var=1/(sj/sigma_y_2[m-1]+1/sigma_alpha_2[m-1]) > temp=0 > for(i in 1:N){temp=temp+1*(source[i]==j)*(y[i]-betamcmc[m-1]*x[i])} > #sum up (y_i-beta x_i ) for those belonging to group j > mean=var*(temp/sigma_y_2[m-1]+mu_alpha[m-1]/sigma_alpha_2[m-1]) > alphamcmc[m,j]=rnorm(1,mean,sqrt(var)) > } > #update beta > var=sigma_alpha_2[m-1]/(sum(x^2)) > mean=sum(x%*%(y-alphamcmc[m,source])/sum(sum(x^2))) > betamcmc[m]=rnorm(1,mean,sqrt(var)) > #update mu_alpha > #update sigma_alpha_2 > sigma_alpha_2[m]=rinvgamma(1,shape=J/2,rate=sum((alphamcmc[m,] > -mu_alpha[m])^2/2)) > #update sigma_y_2 > sigma_y_2[m]=rinvgamma(1,shape=N/2,rate=sum((y-alphamcmc[m,source]- > betamcmc[m]*x)^2/2)) > } > nburn=200 > apply(alphamcmc[(nburn+1):iter,],2,mean) > apply(betamcmc[(nburn+1):iter],2,mean) > > Ive been searching for wrong spaces or tabulations, but I was not able to > find anything. > > I really would appreciate your help. > Thaknk you. > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Whitespace
Hello Ive been working on a stan program in Rstudio. Im kind of new on this, so probably my question is trivial, However I was not able to find information about this. The error Im getting when I run my stan code is: PARSER EXPECTED: whitespace to end of file. FOUND AT line 2: The code is: iter=500 alphamcmc=matrix(0,ncol=J,nrow=iter) betamcmc=NULL mu_alpha=NULL sigma_alpha_2=NULL sigma_y_2=NULL #set initial values alphamcmc[1,]=rep(mean(y),J) betamcmc[1]=70 mu_alpha[1]=mean(y) sigma_alpha_2[1]=300 sigma_y_2[1]=350 #mcmc iteration for(m in 2:iter){ #update alpha vector for(j in 1:J){ sj=sum(source==j) var=1/(sj/sigma_y_2[m-1]+1/sigma_alpha_2[m-1]) temp=0 for(i in 1:N){temp=temp+1*(source[i]==j)*(y[i]-betamcmc[m-1]*x[i])} #sum up (y_i-beta x_i ) for those belonging to group j mean=var*(temp/sigma_y_2[m-1]+mu_alpha[m-1]/sigma_alpha_2[m-1]) alphamcmc[m,j]=rnorm(1,mean,sqrt(var)) } #update beta var=sigma_alpha_2[m-1]/(sum(x^2)) mean=sum(x%*%(y-alphamcmc[m,source])/sum(sum(x^2))) betamcmc[m]=rnorm(1,mean,sqrt(var)) #update mu_alpha #update sigma_alpha_2 sigma_alpha_2[m]=rinvgamma(1,shape=J/2,rate=sum((alphamcmc[m,] -mu_alpha[m])^2/2)) #update sigma_y_2 sigma_y_2[m]=rinvgamma(1,shape=N/2,rate=sum((y-alphamcmc[m,source]- betamcmc[m]*x)^2/2)) } nburn=200 apply(alphamcmc[(nburn+1):iter,],2,mean) apply(betamcmc[(nburn+1):iter],2,mean) Ive been searching for wrong spaces or tabulations, but I was not able to find anything. I really would appreciate your help. Thaknk you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-help Digest, Vol 170, Issue 29
> Message: 1 > Date: Fri, 28 Apr 2017 11:07:40 + > From: T.Riedle > To: "R-help@r-project.org" > Subject: [R] Augmented Dickey Fuller test > Message-ID: <1493377701072.16...@kent.ac.uk> > Content-Type: text/plain; charset="UTF-8" > > Dear all, > > I am trying to run an ADF test using the adf.test() function in the tseries > package and the ur.df() function in the urca package. The results I get > contrast sharply. Whilst the adf.test() indicates stationarity which is in > line with the corresponding graph, the ur.df() indicates non-stationarity. > In a simple example I can't reproduce your finding. The test statistic of adf.test() and ur.df() are identical: > library(urca) > library(tseries) > > set.seed(1) > > x <- rnorm(1000) # no unit-root > adf.test(x) Augmented Dickey-Fuller Test data: x Dickey-Fuller = -9.9291, Lag order = 9, p-value = 0.01 alternative hypothesis: stationary Warning message: In adf.test(x) : p-value smaller than printed p-value > ur.df(x, lags=trunc((length(x)-1)^(1/3)), type="trend") ### # Augmented Dickey-Fuller Test Unit Root / Cointegration Test # ### The value of the test statistic is: -9.9291 32.869 49.2953 > > y <- diffinv(x) # contains a unit-root > adf.test(y) Augmented Dickey-Fuller Test data: y Dickey-Fuller = -2.5115, Lag order = 9, p-value = 0.3618 alternative hypothesis: stationary > ur.df(y, lags=trunc((length(y)-1)^(1/3)), type="trend") ### # Augmented Dickey-Fuller Test Unit Root / Cointegration Test # ### The value of the test statistic is: -2.5115 2.4203 3.5281 > > > Why does this happen? Could anybody explain the adf.test() function in more > detail? How does adf.test() select the number of lags is it AIC or BIC and > how does it take an intercept and/or a trend into account? ?adf.test Details The general regression equation which incorporates a constant and a linear trend is used and the t-statistic for a first order autoregressive coefficient equals one is computed. The number of lags used in the regression is k. The default value of trunc((length(x)-1)^(1/3)) corresponds to the suggested upper bound on the rate at which the number of lags, k, should be made to grow with the sample size for the general ARMA(p,q) setup. References A. Banerjee, J. J. Dolado, J. W. Galbraith, and D. F. Hendry (1993): Cointegration, Error Correction, and the Econometric Analysis of Non-Stationary Data, Oxford University Press, Oxford. S. E. Said and D. A. Dickey (1984): Testing for Unit Roots in Autoregressive-Moving Average Models of Unknown Order. Biometrika 71, 599–607. > > > > Help is greatly appreciated. > > > > Thanks in advance. > > [[alternative HTML version deleted]] > Best regards Adrian -- Adrian Trapletti Steinstrasse 9b, 8610 Uster, Switzerland P +41 44 994 56 30 | M +41 79 103 71 31 adr...@trapletti.org | www.trapletti.org __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Lattice xyplot
Dear all, I am new to lattice, so would appreciate anyone's help on the questions below. I am using xyplot to plot some trend in my dataset. Using the example dataset attached, I am trying to plot variable "y" over variable "time" for each subject "id": dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL) xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") It appears that it just worked fine. But if I sort the "dat" first, the plot will look somewhat different! dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"), xlab = "Time", ylab = "Y") Why is that? Do you need to sort the data first before using xyplot? Why xyplot can not understand the dataset unless it is sorted first? Thanks, Johnid timey 107 0 6.5 107 1 5.1 107 2 4.2 112 0 5.6 107 3 6.9 112 1 4 112 2 1 119 0 7.6 112 3 4.9 119 1 5.7 120 0 7.1 203 0 7.4 120 2 2.1 203 1 6.3 123 0 6.8 203 2 3.8 119 3 6.1 123 1 3.9 123 2 3 120 3 6 203 3 7.6 207 0 5.8 207 1 3.1 123 3 5.7 209 3 3.6 208 0 4.4 130 0 5.5 131 0 6.9 133 0 5.7 134 0 5.1 209 0 4.9 128 2 2.9 128 1 4.5 130 2 5.9 131 1 6.9 133 2 2.6 133 1 5.7 403 2 3.1 403 0 4.5 128 0 4.5 134 2 2.3 207 3 4.8 130 3 4.9 207 2 2.3 130 1 3.8 131 2 3.9 133 3 3.1 134 1 2.8 209 1 4.2 208 3 2.3 208 1 5.3 208 2 0.8 128 3 4.4 131 3 6.2 209 2 5.7 134 3 4.1 403 3 2.5 119 2 2.3 120 1 3.8 403 1 3.2 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finding nrows with specefic values&converting a matrix into a table
I'm trying to write the table I have created from the matrix using write.table(mytable, file= "mytable.txt"). I have imported this txt. file into an Excel sheet but all data have been typed in one column (Var1,Var2,&Freq.) and I want to see each vector in one column. Have I used the correct syntax? Regards From: David L Carlson Sent: 30 April 2017 07:33 PM To: abo dalash; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table Show us the code you used. Don't just tell us what you did. It is likely that something you did after creating the matrix converted it to a data frame. Copy and paste your code to your emails. > str(mydf) 'data.frame': 3 obs. of 3 variables: $ x: int 0 NA NA $ y: int 5 0 NA $ z: int 67 23 0 > data.frame(as.table(as.matrix(mydf))) Var1 Var2 Freq 1xx0 2yx NA 3zx NA 4xy5 5yy0 6zy NA David C From: abo dalash [mailto:abo_d...@hotmail.com] Sent: Sunday, April 30, 2017 11:13 AM To: David L Carlson Subject: Re: [R] Finding nrows with specefic values&converting a matrix into a table str(mymatrix) The Structure shows that this is a 'data.frame'? of 120 obs. and 120 variables of numeric type. R deals with my matrix as a data frame although I used the function matrix() to produce this matrix which is not clear to me why. As this is already a data.frame, this may explains why R returns me the same matrix. What do you recommend now? Many thanks From: David L Carlson Sent: 30 April 2017 06:47 PM To: abo dalash; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table You did not give me any information about about your data using str() or class() so I'll guess that you have a matrix, e.g.: > class(moredata) [1] "matrix" > as.data.frame.table(moredata) Var1 Var2 Freq 1xx0 2yx NA 3zx NA 4xy5 5yy0 6zy NA 7xz 67 8yz 23 9zz0 David C From: abo dalash [mailto:abo_d...@hotmail.com] Sent: Sunday, April 30, 2017 10:09 AM To: David L Carlson ; r-help@R-project.org Subject: Re: [R] Finding nrows with specefic values&converting a matrix into a table Dear David .., Many thanks for this detailed answer. Your guidance reg. the first task has resolved my issue and I have understood now how to perform this type of analysis. I have saved your learning tips in my script. Reg. the Matrix-table conversion, could you please clarify this more?. I applied the function as.data.frame but this returned the same matrix without converting it into a list table. I'm not sure where is the problem in my code : mymatrix <- as.data.frame(mymatrix). Many thanks for your support Regards From: David L Carlson Sent: 29 April 2017 11:38 PM To: abo dalash; r-help@R-project.org Subject: RE: [R] Finding nrows with specefic values&converting a matrix into a table First. Do not use html messages, only plain text. Second. Provide a small example data set, preferably using dput(). Just printing your data can hide important information. Third. Read the documentation. Your first example does not return a logical vector at all: > dput(mydata) structure(list(Col1 = c(123L, 443L, 566L), Col2 = c(566L, 54L, 44L), Col3 = c(235L, 566L, 235L)), .Names = c("Col1", "Col2", "Col3"), class = "data.frame", row.names = c(NA, -3L)) > which(mydata == 566,235) row col [1,] 3 1 [2,] 1 2 [3,] 2 3 It locates cells with 566, but not 235 which is not a surprise because you did not provide a valid logical expression to which(). There are a number of ways to get what you want, but since you want to process rows, apply() is straightforward: > Val566 <- apply(mydata, 1, function(x) any(x == 566)) > Val566 [1] TRUE TRUE TRUE > Val235 <- apply(mydata, 1, function(x) any(x == 235)) > Val235 [1] TRUE FALSE TRUE > which(Val235 & Val566) [1] 1 3 You should read the manual pages on any(), apply(), dput() and which() and logical expressions: > ?apply > ?any > ?dput > ?which > ?Comparison # ?"==" will also get you there. For the second question, assuming you are beginning with a table object as R defines that term and not a matrix (since all tables are matrices, but all matrices are not tables): > dput(moredata) structure(c(0L, NA, NA, 5L, 0L, NA, 67L, 23L, 0L), .Dim = c(3L, 3L), .Dimnames = list(c("x", "y", "z"), c("x", "y", "z")), class = "table") > moredata x y z x 0 5 67 y NA 0 23 z NA NA 0 Note, that your example uses na rather than NA. R is case sensitive so na is just an ordinary character string while NA is a missing value indicator. This is one of the reasons that dput() is important > moredata.df <- as.data.frame(moredata) > moredata.df Var1 Var2 Freq 1xx0 2yx NA 3