[R] permutation test for PLS/PLSDA
Hi, Is there any R package doing permutation/randomization test for PLS/PLSDA? I found some codes for MatLab, but I want to use R program. Thank you very much in advance. Kohkichi Hosoda __ R-help@r-project.org mailing list 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] Display of data points in the Scatterplot
On 2012-12-19 12:31, David Winsemius wrote: On Dec 19, 2012, at 11:28 AM, Katherine Gobin wrote: Respected R forum I am learning R and relatively quite new to R. I am generating a scatter-plot as given below. (My actual table is much larger). # Sample data frame y = c(20, 23, 17, 31, 68) x = c(200, 300, 400, 500, 600) plot(x, y, type = 'l') If I plot this scatter-plot in excel, the data values are displayed if I place the cursor at some desired place of the graph. E.g. if I place the cursor say at the point (400, 31), then the value (400, 31) is displayed. My question(s) are easily answered by looking at the help pages. (A) once I plot a graph in R, is it possible to display a particular (x, y) co-ordinate by placing the cursor there? ?locator Shouldn't that be ?identify? And the OP might also want to check out the HWidentify/HTKidentify functions in the TeachingDemos package. Peter Ehlers (B) Suppose I have 100 pairs of (x, y ). then is it possible to display in the graph (irrespective of the curosr position) the values of (x, y) corresponding to say 10th, 20th, 30th, 40th etc. observations in the graph. ?text ?"%/% __ R-help@r-project.org mailing list 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] Character Variable in X axis scatter plot
Function strptime() will convert the date-time character string to a POSIXct object that you can use in your plot. In general, when posting a query to r-help: 1. Do not use html, only plain text (see what happened to your data below. 2. Use dput() to convert your data to a format that is easy to import from an email message. -- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of John Jeffery > Sent: Saturday, December 22, 2012 5:47 PM > To: r-help@r-project.org > Subject: [R] Character Variable in X axis scatter plot > > > I am very new to R statistics. > Have installed R-2.15.2 ; Rcmdr 1.9-2 ; RStudio 0.97.237 on Debian > Squeeze and also windows7 > > I can Import from Excel File OK > > .Workbook <- loadWorkbook("/media/4C90-B739/Oct13-Dec21Bsl.xls") > JJData <- readWorksheet(.Workbook, "Oct13-Dec21Bsl") > remove(.Workbook) > > have a data frame with following. > > > > > > > > > > > > > > > > > DATEEVENT > AdjDateTime > TIMESLOT > EVENTTYPE > KEY0 > BSLmmol/L > > > 41195.302778 > 13/10/2012 7:16 > 1 > 1 > 278 > 15.44 > > > 41195.490972 > 13/10/2012 11:47 > 2 > 1 > 327 > 18.17 > > > 41196.37 > 14/10/2012 8:48 > 1 > 1 > 246 > 13.67 > > > 41196.492361 > 14/10/2012 11:49 > 2 > 1 > 353 > 19.61 > > > 41196.641667 > 14/10/2012 15:24 > 4 > 1 > 204 > 11.33 > > > 41197.296528 > 15/10/2012 7:07 > 1 > 1 > 244 > 13.56 > > > 41197.297917 > 15/10/2012 7:09 > 1 > 1 > 237 > 13.17 > > > > > > want to plot adjDateTime on x-axis versus BSLmmol/L on Y-axis > > How do I use Character variable "AdjDateTime" as X-variable axis on > scatter plot. > Thanks and regards John Jeffery > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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 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] correction needed in codes
Dear useRs,while trying to plot the yearly curves of 1000 stations and overlapping each set of curves with mean curve and then saving it automatically in a pdf file, i tried the following commands >Path = "C:\\R\\003.pdf">pdf(file=Path) for (i in seq(1:1000) >a<-lapply(seq_along(tcp), function(x) tcp[[x]][,-1]) >b<-lapply(seq_along(a), function(a) matrix(rowMeans(tcp[[a]]),ncol=1)) >lapply(seq_along(tcp), function(i) (matplot(tcp[[i]][,-1], type="l",col="grey") ) >lines(b, lwd=2, type="l")) } >dev.off()although i was successful in plotting yearly curves of each station, but overlapping them with the mean curves still remains an issue.kindly guide me what kind of improvement is needed in my codes.thanks in advance regardseliza [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Character Variable in X axis scatter plot
I am very new to R statistics. Have installed R-2.15.2 ; Rcmdr 1.9-2 ; RStudio 0.97.237 on Debian Squeeze and also windows7 I can Import from Excel File OK .Workbook <- loadWorkbook("/media/4C90-B739/Oct13-Dec21Bsl.xls") JJData <- readWorksheet(.Workbook, "Oct13-Dec21Bsl") remove(.Workbook) have a data frame with following. DATEEVENT AdjDateTime TIMESLOT EVENTTYPE KEY0 BSLmmol/L 41195.302778 13/10/2012 7:16 1 1 278 15.44 41195.490972 13/10/2012 11:47 2 1 327 18.17 41196.37 14/10/2012 8:48 1 1 246 13.67 41196.492361 14/10/2012 11:49 2 1 353 19.61 41196.641667 14/10/2012 15:24 4 1 204 11.33 41197.296528 15/10/2012 7:07 1 1 244 13.56 41197.297917 15/10/2012 7:09 1 1 237 13.17 want to plot adjDateTime on x-axis versus BSLmmol/L on Y-axis How do I use Character variable "AdjDateTime" as X-variable axis on scatter plot. Thanks and regards John Jeffery [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Regression Modeling Strategies 3-Day Short Course March 2013
*RMS Short Course 2013* Frank E. Harrell, Jr., Ph.D., Professor and Chair Department of Biostatistics, Vanderbilt University School of Medicine *March 4, 5 & 6, 2013* 8:00am - 4:30pm Student Life Center Board of Trust Room Vanderbilt University Nashville Tennessee USA See http://biostat.mc.vanderbilt.edu/2013RMSShortCourse for details. The course includes statistical methodology, case studies, and use of the R rms package. Please email interest to Eve Anderson { eve.a.ander...@vanderbilt.edu } -- Frank E Harrell Jr Professor and Chairman School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list 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] plotting and saving diagrams automatically
On Dec 22, 2012, at 12:34 PM, eliza botto wrote: > > [if the format of my email is changed or is difficult to understand, a text > file is attached for easy understanding]Dear useRs, > i was wondering that if its possible in R to automatically generate plots and > get it saved at the desired location? i have > data of cancer patients, from about 1000 cities around the world. i have > converted that data into a list (called tcp) and > that list has 1000 sublists. the sublists are named, according to the city > name. the orientation of the sublists are as > follow > $ Tokyo > month 2009201020111 515 356 1212444 145 1203 > 478 147 1244147 236 1245785 142 1256478 > 111 4787478 856 7858147 786 4569147 122 > 12310 786 123 14711 123 787 25812 110 898 > 369 > $ Nagoya > month 1955195619641 512 444 7712441 145 4703 > 445 156 4744145 236 7845785 147 4456447 > 178 9887478 980 8858189 886 7869145 722 > 18310 756 123 16711 145 127 24812 110 128 > 259 > what i wanted to do is the following > > 1- drawing curve of each column in the sublist against the first column of > each sublist(month vs patients). > 2- drawing average curve of each city over the yearly curves. (for example, > for tokyo, overlay average curve of 2009,2010 > and 2011 on already generated 3 curves). > 3-saving the resulting diagram on a suitable location in my pc. > i used the following commands for these three operations >> jpeg("C:/world survey/ Tokyo.jpg")>matplot(tcp$ Tokyo[,-1], type = "l", >> col="grey", xlab="TIME(month)", >> ylab="patients")>apply(Tokyo,1,mean)>data.frame(Tokyo)>avgTokyo<-as.matrix(Tokyo, >> ncol=1)>lines(avgTokyo, lwd = 2) > As as you can see that i have 1000 cities to work on, isnt there any other > suitable way of doing that??i am interested in knowing about "function" > command. because when i used the following command >> lapply(seq_along(tcp), function(i) matplot(tcp[[i]][,1],tcp[[i]][,-1], >> type="l",col="grey")) > i did plot every city' diagram but didnt save it anywhere. > Could you please guide me how to plot and save simultaneously all the firgure > in one go? The 'pdf' function would allow you to make multi-page objects, arguably more useful than the startegy you are proposing. Or you could use your loop to construct names for 1000 separate jpeg files. lapply( names(tcp), function(i) filnam <- paste0(i, ".jpg") jpeg(filnam) matplot(tcp[[i]][,1],tcp[[i]][,-1], type="l",col="grey") dev.off() ) If you didn't use the names you will not be able to recover them inside the function, since only the object itself is passed. -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list 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] Does R have an equivalent for Matlab's cell array?
HI, May be this helps: dat1 <- read.table(text=" 20100914 08:01, 3.74 20100914 08:11, 3.74 20100914 08:21, 3.71 20100914 08:31, 4.39 20100914 08:41, 3.74 20100915 08:01, 3.64 20100915 08:11, 3.54 20100915 08:21, 3.61 20100915 08:31, 4.49 20100915 08:41, 3.84 ", sep=",",header=FALSE,stringsAsFactors=FALSE) tapply(dat1$V2,list(as.Date(dat1$V1,format="%Y%m%d %H:%M")),function(x) x) #$`2010-09-14` #[1] 3.74 3.74 3.71 4.39 3.74 # #$`2010-09-15` #[1] 3.64 3.54 3.61 4.49 3.84 A.K. - Original Message - From: Matthijs Daelman To: r-help@r-project.org Cc: Sent: Saturday, December 22, 2012 5:58 AM Subject: [R] Does R have an equivalent for Matlab's cell array? Hi I have a time series of measurements: every 10 min. a value was logged. The data look like: 20100914 08:01 3.74 20100914 08:11 3.74 20100914 08:21 3.71 20100914 08:31 4.39 20100914 08:41 3.74 This data spans several months. I would like to group the data per day. In Matlab it is fairly easy to obtain a cell array, of which the first column contains the date of each day, and the second column contains a vector, that in its turn contains all values for the corresponding day. That looks like 14-9-2010 [3.74 3.74 3.71 4.39 3.74...] 15-9-2010 [...] and so on. Is it possible to create a similar data structure in in R? I was thinking of a data frame, similar to the Matlab's cell array, but it doesn't look like data frames can contain vectors. Something like a two dimensional list would do the trick, I believe, but does that exist? Thanks Kind regards Matthijs Daelman __ R-help@r-project.org mailing list 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 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] plotting and saving diagrams automatically
[if the format of my email is changed or is difficult to understand, a text file is attached for easy understanding]Dear useRs, i was wondering that if its possible in R to automatically generate plots and get it saved at the desired location? i have data of cancer patients, from about 1000 cities around the world. i have converted that data into a list (called tcp) and that list has 1000 sublists. the sublists are named, according to the city name. the orientation of the sublists are as follow $ Tokyo month 2009201020111 515 356 1212444 145 1203 478 147 1244147 236 1245785 142 1256478 111 4787478 856 7858147 786 4569147 122 12310 786 123 14711 123 787 25812 110 898 369 $ Nagoya month 1955195619641 512 444 7712441 145 4703 445 156 4744145 236 7845785 147 4456447 178 9887478 980 8858189 886 7869145 722 18310 756 123 16711 145 127 24812 110 128 259 what i wanted to do is the following 1- drawing curve of each column in the sublist against the first column of each sublist(month vs patients). 2- drawing average curve of each city over the yearly curves. (for example, for tokyo, overlay average curve of 2009,2010 and 2011 on already generated 3 curves). 3-saving the resulting diagram on a suitable location in my pc. i used the following commands for these three operations >jpeg("C:/world survey/ Tokyo.jpg")>matplot(tcp$ Tokyo[,-1], type = "l", >col="grey", xlab="TIME(month)", >ylab="patients")>apply(Tokyo,1,mean)>data.frame(Tokyo)>avgTokyo<-as.matrix(Tokyo, > ncol=1)>lines(avgTokyo, lwd = 2) As as you can see that i have 1000 cities to work on, isnt there any other suitable way of doing that??i am interested in knowing about "function" command. because when i used the following command >lapply(seq_along(tcp), function(i) matplot(tcp[[i]][,1],tcp[[i]][,-1], >type="l",col="grey")) i did plot every city' diagram but didnt save it anywhere. Could you please guide me how to plot and save simultaneously all the firgure in one go? thanks in advance eliza Dear useRs, i was wondering that if its possible in R to automatically generate plots and get it saved at the desired location? i have data of cancer patients, from about 1000 cities around the world. i have converted that data into a list (called tcp) and that list has 1000 sublists. the sublists are named, according to the city name. the orientation of the sublists are as follow $ Tokyo month 200920102011 1 515 356 121 2 444 145 120 3 478 147 124 4 147 236 124 5 785 142 125 6 478 111 478 7 478 856 785 8 147 786 456 9 147 122 123 10 786 123 147 11 123 787 258 12 110 898 369 $ Nagoya month 195519561964 1 512 444 771 2 441 145 470 3 445 156 474 4 145 236 784 5 785 147 445 6 447 178 988 7 478 980 885 8 189 886 786 9 145 722 183 10 756 123 167 11 145 127 248 12 110 128 259 what i wanted to do is the following 1- drawing curve of each column in the sublist against the first column of each sublist(month vs patients). 2- drawing average curve of each city over the yearly curves. (for example, for tokyo, overlay average curve of 2009,2010 and 2011 on already generated 3 curves). 3-saving the resulting diagram on a suitable location in my pc. i used the following commands for these three operations >jpeg("C:/world survey/ Tokyo.jpg") >matplot(tcp$ Tokyo[,-1], type = "l", col="grey", xlab="TIME(month)", >ylab="patients") >apply(Tokyo,1,mean) >data.frame(Tokyo) >avgTokyo<-as.matrix(Tokyo, ncol=1) >lines(avgTokyo, lwd = 2) As as you can see that i have 1000 cities to work on, isnt there any other suitable way of doing that?? i am interested in knowing about "function" command. because when i used the following command >lapply(seq_along(tcp), function(i) matplot(tcp[[i]][,1],tcp[[i]][,-1], >type="l",col="grey")) i did plot every city' diagram but didnt save it anywhere. Could you please guide me how to plot and save simultaneously all the firgure in one go? thanks in advance eliza __ R-help@r-project.org mailing list 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] Does R have an equivalent for Matlab's cell array?
Hello, Something like this? dat <- read.table(text=" 20100914 08:01 3.74 20100914 08:11 3.74 20100914 08:21 3.71 20100914 08:31 4.39 20100914 08:41 3.74 ") dat split(dat$V3, dat$V1) This gives you a list where each element is a (1-dimensional) vector, and each of those vectors can have any length, not necessarily the same. Hope this helps, Rui Barradas Em 22-12-2012 10:58, Matthijs Daelman escreveu: Hi I have a time series of measurements: every 10 min. a value was logged. The data look like: 20100914 08:01 3.74 20100914 08:11 3.74 20100914 08:21 3.71 20100914 08:31 4.39 20100914 08:41 3.74 This data spans several months. I would like to group the data per day. In Matlab it is fairly easy to obtain a cell array, of which the first column contains the date of each day, and the second column contains a vector, that in its turn contains all values for the corresponding day. That looks like 14-9-2010[3.74 3.74 3.71 4.39 3.74...] 15-9-2010[...] and so on. Is it possible to create a similar data structure in in R? I was thinking of a data frame, similar to the Matlab's cell array, but it doesn't look like data frames can contain vectors. Something like a two dimensional list would do the trick, I believe, but does that exist? Thanks Kind regards Matthijs Daelman __ R-help@r-project.org mailing list 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 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] Does R have an equivalent for Matlab's cell array?
On Dec 22, 2012, at 2:58 AM, Matthijs Daelman wrote: > Hi > > I have a time series of measurements: every 10 min. a value was logged. > > The data look like: > > 20100914 08:01 3.74 > 20100914 08:11 3.74 > 20100914 08:21 3.71 > 20100914 08:31 4.39 > 20100914 08:41 3.74 > > This data spans several months. > > I would like to group the data per day. In Matlab it is fairly easy to obtain > a cell array, of which the first column contains the date of each day, and > the second column contains a vector, that in its turn contains all values for > the corresponding day. > > That looks like > > 14-9-2010[3.74 3.74 3.71 4.39 3.74...] > 15-9-2010[...] > and so on. > > Is it possible to create a similar data structure in in R? I was thinking of > a data frame, similar to the Matlab's cell array, but it doesn't look like > data frames can contain vectors. That's a surprising conclusion. Vectors are typical components of dataframes. > Something like a two dimensional list would do the trick, I believe, but does > that exist? A dataframe _is_ a two-dimensional list. You should probably explain what you are trying to do, since there is very possibly a better way of structuring this problem without recasting the data into a "wide format". Most of the data processing in R is handled very well without such a strategy. If you wanted to proceed despite my misgivings, then there are several functions such as `split`, `tapply` and `by` that could allow you to segregate such data. It's best to use dput to present the data since console output is often ambiguous as to the underlying data structures. >From what you have offered it's not clear that you have yet done the data >input processing. -- David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list 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] creating a function
Hello, It's a bad idea to name a function and one of it's arguments Y, use Yfun and Y. What does summation(x(Y.t, Y.t-1, ...)) mean? Is there a multiplication sign between x and (Y.t, ...)? And is epsilon a vector of errors, one for each Y.t? If so, the following might do it. Yfun <- function(Y, p, x, epsilon){ for (i in 2:length(Y)) { Y[i] <- Y[i-1] + (1/p)*sum(x*Y[1:(i-1)]) + epsilon[i] } Y } Hope this helps, Rui Barradas Em 22-12-2012 09:29, Simone Gogna escreveu: > Dear R users, > IâEUR^(TM)d like to create a function as: > > Y.t+1 = Y.t + (1\p)*summation(x(Y.t,Y.t-1,...)) + epsilon.t > > where x is a function of Y.t, Y.t-1 and so on, epsilon is a random error and > p is a parameter. > > Do you think something of the following form might be appropriate? > > Y<-function(Y,p,x,epsilon){ > for (i in 2:length(Y)) { > Y[i]<-Y[i-1]+(1/p)*sum(x(Y[i-1]))+epsilo.t} > Y > } > > Any indication is warmly appreciated. > > thanks and best regards > [[alternative HTML version deleted]] > > > > __ > R-help@r-project.org mailing list > 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 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] Does R have an equivalent for Matlab's cell array?
Data frames are lists of vectors. You can have the vectors in a data frame be of mode list, if you wish. It would be more conventional to simply make the list and not put it into the data frame, since columns of mode list give write.table fits. I prefer to simply keep the first form of your data and augment it with a Day column. Then if I want information on a per-day basis I use aggregate from base or ddply from the plyr package. Although I prefer your first form (long format) there are many cases where it makes sense to put groups of data values in separate columns (wide format). You can use the reshape2 package for transforming back and forth. You may also want to check out the Time Series task view on CRAN. Most of those classes work with data in array representation for high speed. --- 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 --- Sent from my phone. Please excuse my brevity. Matthijs Daelman wrote: >Hi > >I have a time series of measurements: every 10 min. a value was logged. > >The data look like: > >20100914 08:01 3.74 >20100914 08:11 3.74 >20100914 08:21 3.71 >20100914 08:31 4.39 >20100914 08:41 3.74 > >This data spans several months. > >I would like to group the data per day. In Matlab it is fairly easy to >obtain a cell array, of which the first column contains the date of >each >day, and the second column contains a vector, that in its turn contains > >all values for the corresponding day. > >That looks like > >14-9-2010[3.74 3.74 3.71 4.39 3.74...] >15-9-2010[...] >and so on. > >Is it possible to create a similar data structure in in R? I was >thinking of a data frame, similar to the Matlab's cell array, but it >doesn't look like data frames can contain vectors. Something like a two > >dimensional list would do the trick, I believe, but does that exist? > >Thanks > >Kind regards > >Matthijs Daelman > >__ >R-help@r-project.org mailing list >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 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] remove from column a group of elements I have in another vector
Thank you Sarah!! My data frame is b and I have to remove from column anslogin every value from vector quit b= ht dispsplit anslogin month_ 1038 162 4627 1 475 1 4305 1 205 103 4136 1 296 1 4627 1 784 9 51274 1 451 75 4593 1 quit= 4079 4081 4095 4096 4119 4134 So, i should do b[!(b$ansologin%in%quit),], right? How does the %in% work??? Is it a normal in and the not comes with the ! ate the beggining? I have never used it, so thanks for teaching me this!. Thanks again, Estefania From: Sarah Goslee To: Estefanía Gómez Galimberti Cc: "r-help@r-project.org" Sent: Friday, December 21, 2012 4:56 PM Subject: Re: [R] remove from column a group of elements I have in another vector You can probably do it with not in in R too: for a data frame x where you want to remove rows where values in column A are not in the vector y: x[!(x$A %in% y), ] If you'd provided a reproducible example, I could give code that works in your particular circumstance. Sarah On Fri, Dec 21, 2012 at 12:43 PM, Estefanía Gómez Galimberti wrote: > Hi, > > I have a data frame and I would need to remove from one of > the columns a group of elements I have in another vector. How can I do that? > I know how to do it with criteria but i would need to do it in a more > automatic way > In SQL I would use where > not in > > Thank you, > Estefania -- Sarah Goslee http://www.functionaldiversity.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] creating a function
Dear R users, Iâd like to create a function as: Y.t+1 = Y.t + (1\p)*summation(x(Y.t,Y.t-1,...)) + epsilon.t where x is a function of Y.t, Y.t-1 and so on, epsilon is a random error and p is a parameter. Do you think something of the following form might be appropriate? Y<-function(Y,p,x,epsilon){ for (i in 2:length(Y)) { Y[i]<-Y[i-1]+(1/p)*sum(x(Y[i-1]))+epsilo.t} Y } Any indication is warmly appreciated. thanks and best regards [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Does R have an equivalent for Matlab's cell array?
Hi I have a time series of measurements: every 10 min. a value was logged. The data look like: 20100914 08:01 3.74 20100914 08:11 3.74 20100914 08:21 3.71 20100914 08:31 4.39 20100914 08:41 3.74 This data spans several months. I would like to group the data per day. In Matlab it is fairly easy to obtain a cell array, of which the first column contains the date of each day, and the second column contains a vector, that in its turn contains all values for the corresponding day. That looks like 14-9-2010[3.74 3.74 3.71 4.39 3.74...] 15-9-2010[...] and so on. Is it possible to create a similar data structure in in R? I was thinking of a data frame, similar to the Matlab's cell array, but it doesn't look like data frames can contain vectors. Something like a two dimensional list would do the trick, I believe, but does that exist? Thanks Kind regards Matthijs Daelman __ R-help@r-project.org mailing list 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] RGoogleTrends error in "getGTrends"
Hi Tal, did you get an answer to this? I'm having a similar problem. Christoph On Thursday, November 3, 2011 11:55:17 AM UTC+1, Tal Galili wrote: > > Hi all, > > I've just installed RGoogleTrends Version:0.2-1 (after compiling it for > windows). > And when running the most basic command I get the following error: > > >ans = getGTrends("coupon") > Error in curlPerform(url = url, curl = curl, .opts = .opts) : > embedded nul in string: 'Y' > In addition: Warning message: > RS-DBI driver warning: (closing pending result sets before closing this > connection) > > > Am I missing something, or is this due to some change in Rgoogletrends > website? > > p.s: any chance there is a Rgoogleinsights alternative? (for > http://www.google.com/insights/search/) I wasn't able to find any. > > > Thanks in advance, > Tal > > > Contact > Details:--- > Contact me: tal.g...@gmail.com | 972-52-7275845 > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | > www.r-statistics.com (English) > > -- > > [[alternative HTML version deleted]] > > __ > r-h...@r-project.org mailing list > 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 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] remove from column a group of elements I have in another vector
Well, you could try it to see what happens... First look at: b$ansologin%in%quit then !(b$ansologin%in%quit) and finally b[!(b$ansologin%in%quit),] You could also read the help ?"!" ?"%in%" and the Intro to R manual that came with R when you installed it. Sarah On Sat, Dec 22, 2012 at 10:48 AM, Estefanía Gómez Galimberti wrote: > Thank you Sarah!! > > My data frame is b and I have to remove from column anslogin every value > from vector quit > > b= > ht dispsplit anslogin month_ > 1038 162 4627 1 >475 1 4305 1 >205 103 4136 1 >296 1 4627 1 >784 951274 1 > 45175 4593 1 > > quit= > 4079 4081 4095 4096 4119 4134 > > So, i should do b[!(b$ansologin%in%quit),], right? > > How does the %in% work??? Is it a normal in and the not comes with the ! ate > the beggining? I have never used it, so thanks for teaching me this!. > > Thanks again, > Estefania > > > From: Sarah Goslee > To: Estefanía Gómez Galimberti > Cc: "r-help@r-project.org" > Sent: Friday, December 21, 2012 4:56 PM > Subject: Re: [R] remove from column a group of elements I have in another > vector > > You can probably do it with not in in R too: > for a data frame x where you want to remove rows where values in > column A are not in the vector y: > > x[!(x$A %in% y), ] > > If you'd provided a reproducible example, I could give code that works > in your particular circumstance. > > Sarah > > On Fri, Dec 21, 2012 at 12:43 PM, Estefanía Gómez Galimberti > wrote: >> Hi, >> >> I have a data frame and I would need to remove from one of >> the columns a group of elements I have in another vector. How can I do >> that? I know how to do it with criteria but i would need to do it in a more >> automatic way >> In SQL I would use where >> not in >> >> Thank you, >> Estefania > > -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list 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 on PK.fit
Dear all, I have a Pharmokinetics data set where single dose is used for several time points on 8 subjects. I wanted to fit a two compartment model on the data set to see whether it is reasonable. This is the first time to analyze a PK data set and am not familar with various concepts in the compartment models. It seems that PK.fit function in the PK.fit package can be used to fit compartment models. However when I looked up the help file, it does not seem to have any examples and or any other kind of help. Can anyone familiar with this give some hint on the reference of fitting compartment models in R. Thank you very much. Hanna [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Parallel code using parLapply
Many thanks - this did the trick! (Well, besides deleting an erroneous comma in the third to last line;)). Best, C. From: Gabor Grothendieck Cc: "R-help@r-project.org" Sent: Saturday, December 22, 2012 6:02 AM Subject: Re: [R] Parallel code using parLapply > Dear R-users > > I was running into problems with my R code trying to run clh sampling (clhs > package) in parallel mode (=on various data sets simultaneously). > > Here is the code (which I developed with some help:)): > ** > library("clhs") > library("snow") > a <- as.data.frame(replicate(1000, rnorm(20))) > b <- as.data.frame(replicate(1000, rnorm(20))) > c <- as.data.frame(replicate(1000, rnorm(20))) > d <- as.data.frame(replicate(1000, rnorm(20))) > abcd <- list(a, b, c, d) > cl <- makeCluster(4) > results <- parLapply(cl, > X = abcd, > FUN = function(i) { > clhs(x = i, size = round(nrow(i) / 5), iter = 2000, simple = FALSE) > }, > ) > stopCluster(cl) > ** > > Before running the last line, R is throwing an error: "Error in length(x) : > 'x' is missing". Any ideas what I am doing wrong and how to improve? > Loading clhs on the primary does not automatically load it on the workers. Try: clusterEvalQ(cl, library(clhs)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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 with opening more than one SOCK cluster with package snow
On 19/12/2012 18:57, Jannis wrote: Dear list, i have some problems using the snow package to create a SOCK cluster. The errors just occour irregularly but it seems to me that they occour when I try to create more than one cluster on the same machine via different R instances started via submitting LSF jobs to a cluster. Does anyone have an idea how to solve this or where to start digging for solutions? Yes. My guess is that you are starting snow clusters simultaneously. The message gives you a pretty big clue: use different ports for different clusters (it is an option to makeCluster). Also that that it is over a year since snow was superseded by an improved version in package 'parallel', so why are you still using the original? The error messages are: library(snow) cl <- makeCluster(8, type = "SOCK") Error in socketConnection(port = port, server = TRUE, blocking = TRUE, : cannot open the connection Calls: run.call ... makeCluster -> makeSOCKcluster -> newSOCKnode -> socketConnection In addition: Warning message: In socketConnection(port = port, server = TRUE, blocking = TRUE, : port 10187 cannot be opened R version 2.15.1 (2012-06-22) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] snow_0.3-10 Thanks a lot Jannis __ R-help@r-project.org mailing list 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list 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] GLM ERROR
Hello, I'm fitting a logistic regression as follows and I have this error "In predict.lm(object, newdata, se.fit, scale = 1, type = ifelse(type == : prediction from a rank-deficient fit may be misleading" Codes: ##Training fit<- glm(Y.Binary.training~., family=binomial(link="logit"), data=training) pred<-predict(fit, training, type="response") pred pred.train<-cbind(pred, Y.Binary.training) preds<-prediction(as.numeric(pred),as.numeric(Y.Binary.training)) perf<- performance(preds, "auc") perf I get a Roc Curve of 1 which is surprising! ##Testing pred<-predict(fit, testing, type="response") pred pred.test<-cbind(pred, Y.Binary.testing) preds<-prediction(as.numeric(pred),as.numeric(Y.Binary.testing)) perf<- performance(preds, "auc") perf I also get a ROC curve of 1...!!! I'm wondering if there is something wrong in my codes . Thanks a lot and happy holidays! Best,Farnoosh Sheikhi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] setting the margin size in ggplot2
Is it possible to set the margin in ggplot to a fixed size? I create many plots, and I want them to look the same. Especially I want them to have the same left margin, with different labels. But P<-ggplot()+geom_bar(aes(c("short label1","short label2"),runif(2)))+coord_flip() creates a plot with another margin as P<-ggplot()+geom_bar(aes(c("very very very very label1","short label2"),runif(2)))+coord_flip() In the standard plot system margins can be set with par(mar=c(…….)), but this doesn’t work in ggplot2 I thought I could do it with plot.margin, but p+theme(plot.margin= unit(c(0, 0, 0,3), "cm")) doesn’t work,it adds an extra, external margin. Does anyone know a solution? Thanks Frans __ R-help@r-project.org mailing list 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.