Re: [R] R beginner: matrix algebra
Convenient ways of computing both simple and log returns are at the very end of: http://www.portfolioprobe.com/2012/11/05/an-easy-mistake-with-returns/ Those work whether you have a vector or a matrix. Pat On 17/12/2012 17:16, kevj1980 wrote: Hi, I have an n x m matrix of numerical observations. ie. stock prices I wish to convert the matrix of observations to a matrix of simple returns (by taking the differences between (column) observations.) Can any good soul suggest a function for this? -- View this message in context: http://r.789695.n4.nabble.com/R-beginner-matrix-algebra-tp4653335.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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] random sampling vector from any dsitribution
Hi, help is very much appreciated. Thanks in advance!!! rgamma(...) As far as I know with this function (code) one can randomly sample 100 numbers simultanously. Question is: is it possible to sample 100 random numbers e.g. from 100 different gamma distributions using only one command line (or: using only one function)? One idea how this could look like: rgamma(1:100, shape=c(s1,s2,...,s100), rate=c(r1,r2,...,r100)) What I do not know: is it correct to assume that effectively only ONE random number (with the respective paramateres s1s2...s100 und r1r2...r100) has been drawn from 1 gamma distribution (out of 100 various gamma distributions) ? Thanks again for any thoughts and advice! Merry Christmas! -- View this message in context: http://r.789695.n4.nabble.com/random-sampling-vector-from-any-dsitribution-tp4653410.html Sent from the R help mailing list archive at Nabble.com. __ 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] Calculate geographic/euclidian distance between consecutive XY-pairs
Hi, I have a dataframe containing 3 columns: data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5)) where X and Y are coordinates and Time refers to an index of a timestep. Now I would like to get the distance between the consecutive timesteps. This should actually provide a vector of length=4, representing the euclidian resp. geopgraphic distance between the first and the second, and the second and the third timestep and so on... Is there a simple way to calculate this and get the resulting vector as a result? Or can anyone give an example? best regards, /j __ 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] Calculate geographic/euclidian distance between consecutive XY-pairs
On 18/12/2012 10:56 p.m., Johannes Radinger wrote: Hi, I have a dataframe containing 3 columns: data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5)) where X and Y are coordinates and Time refers to an index of a timestep. Now I would like to get the distance between the consecutive timesteps. This should actually provide a vector of length=4, representing the euclidian resp. geopgraphic distance between the first and the second, and the second and the third timestep and so on... Is there a simple way to calculate this and get the resulting vector as a result? Or can anyone give an example? How about something like: coords - data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5)) with(coords, sqrt(diff(X)^2 + diff(Y)^2)) Ray Brownrigg best regards, /j __ 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] Calculate geographic/euclidian distance between consecutive XY-pairs
Hello, Here is a possibility: library(maptools) XY - cbind(X=c(100,102,104,102,103),Y=c(12,14,14,13,16)) dst - spDists(XY[1:4,],XY[2:5,],longlat=TRUE) ?spDists HTH, Pascal Le 18/12/2012 18:56, Johannes Radinger a écrit : Hi, I have a dataframe containing 3 columns: data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5)) where X and Y are coordinates and Time refers to an index of a timestep. Now I would like to get the distance between the consecutive timesteps. This should actually provide a vector of length=4, representing the euclidian resp. geopgraphic distance between the first and the second, and the second and the third timestep and so on... Is there a simple way to calculate this and get the resulting vector as a result? Or can anyone give an example? best regards, /j __ 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] R beginner: matrix algebra
Thanks to all for help. The filter function appears most straightforward way for this problem. Kevin -- View this message in context: http://r.789695.n4.nabble.com/R-beginner-matrix-algebra-tp4653335p4653414.html Sent from the R help mailing list archive at Nabble.com. __ 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] random sampling vector from any dsitribution
On Dec 18, 2012, at 9:07 AM, Kairos2012 lucie.salwic...@zooplus.de wrote: Hi, help is very much appreciated. Thanks in advance!!! rgamma(...) As far as I know with this function (code) one can randomly sample 100 numbers simultanously. Question is: is it possible to sample 100 random numbers e.g. from 100 different gamma distributions using only one command line (or: using only one function)? One idea how this could look like: rgamma(1:100, shape=c(s1,s2,...,s100), rate=c(r1,r2,...,r100)) So close: change 1:100 to simply 100 MW What I do not know: is it correct to assume that effectively only ONE random number (with the respective paramateres s1s2...s100 und r1r2...r100) has been drawn from 1 gamma distribution (out of 100 various gamma distributions) ? Thanks again for any thoughts and advice! Merry Christmas! -- View this message in context: http://r.789695.n4.nabble.com/random-sampling-vector-from-any-dsitribution-tp4653410.html Sent from the R help mailing list archive at Nabble.com. __ 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] syntax for very simple derivative function
Readers, Two variables 'M', 'T', each contain a column of numbers. Have tried to create a derivative function to see how 'M' varies with respect to 'T': dm-D(m)(dm/dt)~dt dm(m=M,t=T) but R returns an error: Error: could not find function dm What is my mistake please? -- R2151 __ 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] Calculate geographic/euclidian distance between consecutive XY-pairs
Hi Ray, thank you very much. That one-line approach is what I was looking for. A very simple but very efficient way without loading any other packages. /j On Tue, Dec 18, 2012 at 11:17 AM, Ray Brownrigg ray.brownr...@ecs.vuw.ac.nz wrote: On 18/12/2012 10:56 p.m., Johannes Radinger wrote: Hi, I have a dataframe containing 3 columns: data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5)) where X and Y are coordinates and Time refers to an index of a timestep. Now I would like to get the distance between the consecutive timesteps. This should actually provide a vector of length=4, representing the euclidian resp. geopgraphic distance between the first and the second, and the second and the third timestep and so on... Is there a simple way to calculate this and get the resulting vector as a result? Or can anyone give an example? How about something like: coords - data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5)) with(coords, sqrt(diff(X)^2 + diff(Y)^2)) Ray Brownrigg best regards, /j __ 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] looping through spatial points and getting counts of spatial points in spatial grid in R
Tilottama Ghosh waggymaggy at yahoo.com writes: Hi, Following Anthony's reply I am attaching two of the POI shapefiles and the code for creating the spatial grid. I am not being able to read the list of these shapefiles and then perform the points in spatial grid function. If someone can help, I will be very grateful. Here is my code for creating the spatial grid -Gridtopo_LS = GridTopology(cellcentre.offset = Please repost your question on the R-sig-geo list, and do follow the posting guide. You should place any files on a web-server, not attach them, and make sure that you do not post HTML messages, only plain text, so that the formatting of your sample code is not disturbed. Roger # Getting a count of the Spatial Points in the Spatial Data Frame in.cell - overlay(SpatialGrid_LS,FinInstq2) newdata - data.frame(table(in.cell))View(newdata) SpatialGrid_LS is the spatial grid that I had created in R. I guess a For loop would help, but although I tried several things, I haven't been successful yet. Thanks! Tilo __ 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] Manipulation of longitudinal data by row
Right you are, A.K. Thanks for catching that. It should be ... data2 - data.frame( id = rep(data1$ID, 3), visit = rep(1:3, rep(dim(data1)[1], 3)), date = as.Date(c(data1$V1Date, data1$V2date, data1$V3date), %m/%d/%y), dva = c(data1$V1a, data1$V2a, data1$V3a), dvb = c(data1$V1b, data1$V2b, data1$V3b), dvc = c(data1$V1c, data1$V2c, data1$V3c)) Jean On Mon, Dec 17, 2012 at 5:08 PM, arun smartpink...@yahoo.com wrote: Hi Jean, Just to clarify whether it is a 'typo' or not. data2 - data.frame( id = rep(data1$ID, 3), visit = rep(1:3, rep(dim(data1)[1], 3)), date = as.Date(c(data1$V1Date, data1$V2date, data1$V3date), %m/%d/%y), dva = c(data1$V1a, data1$V2a, data1$V3a), dvb = c(data1$V1a, data1$V2a, data1$V3a),# 'b' dvc = c(data1$V1a, data1$V2a, data1$V3a)) # 'c' A.K. - Original Message - From: Adams, Jean jvad...@usgs.gov To: marcel curlin marcelcur...@gmail.com Cc: r-help@r-project.org Sent: Monday, December 17, 2012 5:29 PM Subject: Re: [R] Manipulation of longitudinal data by row I had some difficulty getting the data read in using the code you included in your email, although I'm not sure why. I'm pasting in the code that worked for me, below. I think that the calculations that you want to make would be easier if you rearranged your data first. I used your example data to do just that. Once the data are rearranged, it is very easy to look at information on the last visit from each ID (see code, below). This includes much of the information you describe in your query, 1) date of last completed visit 2) whether an ID resolved, and 3) what the final pattern was. Jean tC - textConnection(ID V1Date V1a V1b V1c V2date V2a V2b V2c V3date V3a V3b V3c 001 4/5/12 Yes Yes No 6/18/12 Yes No Yes NA NA NA NA 002 1/22/12 No No Yes 7/5/12 Yes No Yes NA NA NA NA 003 4/5/12 Yes No No 9/4/12 Yes No Yes 11/1/12 Yes No Yes 004 8/18/12 Yes Yes Yes 9/22/12 Yes No Yes NA NA NA NA 005 9/6/12 Yes No No NA NA NA NA 12/4/12 Yes No Yes) data1 - read.table(header=TRUE, tC) close.connection(tC) rm(tC) # rearrange the data data2 - data.frame( id = rep(data1$ID, 3), visit = rep(1:3, rep(dim(data1)[1], 3)), date = as.Date(c(data1$V1Date, data1$V2date, data1$V3date), %m/%d/%y), dva = c(data1$V1a, data1$V2a, data1$V3a), dvb = c(data1$V1a, data1$V2a, data1$V3a), dvc = c(data1$V1a, data1$V2a, data1$V3a)) # define a new variable that is a combination of the three dichotomous variables data2$abc - paste0(substring(data2$dva, 1, 1), substring(data2$dvb, 1, 1), substring(data2$dvb, 1, 1)) # define a new variable that indicates whether the combination is normal data2$normal - data2$abc %in% c(YYN, YNY, YYN, NNY) # eliminate rows without visit information data3 - data2[!is.na(data2$date), ] # split the data into lists according to id list4 - split(data3, data3$id) # show the last visit from each id do.call(rbind, lapply(list4, function(df) df[dim(df)[1], ])) On Fri, Dec 14, 2012 at 10:37 AM, marcel curlin marcelcur...@gmail.com wrote: I have a dataset of the form below, consisting of one unique ID per row, followed by a series of visit dates. At each visit there are values for 3 dichotomous variables. Of the 8 different possible combinations of the three variables, 4 are abnormal and the remaining 4 are normal. Everyone starts out abnormal, and then either continues to be abnormal at subsequent visits, or resolves to a normal pattern at a later visit (I ignore reversion back to abnormal - once they are normal, they are normal) I have to end up with 4 new columns indicating 1) date of last completed visit (regardless of intervening NAs, 2) whether an ID resolved or stayed abnormal, 3) if resolved, what the resolution pattern was and 4) what the date of resolution was. NAs always come in groups of 4 (ie no visit date, and no value for the 3 variables) and are ignored. Eventually I have to determine mean time to resolution, mean follow-up time, etc and I think I can do that, but the first part is a bit beyond my coding skill. Suggestions appreciated. tC - textConnection( ID V1Date V1a V1b V1c V2date V2a V2b V2c V3date V3a V3b V3c 001 4/5/12 Yes Yes No 6/18/12 Yes No Yes NA NA NA NA 002 1/22/12 No No Yes 7/5/12 Yes No Yes NA NA NA NA 003 4/5/12 Yes No No 9/4/12 Yes No Yes 11/1/12 Yes No Yes 004 8/18/12 Yes Yes Yes 9/22/12 Yes No Yes NA NA NA NA 005 9/6/12 Yes No No NA NA NA NA 12/4/12 Yes No Yes ) data1 - read.table(header=TRUE, tC) close.connection(tC) rm(tC) __ 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
Re: [R] Summarizing elements for a data.frame
Hi Christofer, Check ?tapply, ?aggregate and ?ave. Here is a way of doing in using the first function: tapply(Dat1[, 3], list(Dat1[,1], Dat1[,2]), sum, na.rm = TRUE) HTH, Jorge.- On Wed, Dec 19, 2012 at 1:36 AM, Christofer Bogaso wrote: Dat1 - structure(list(factor.sample.LETTERS.1.3...6..replace...T.. = structure(c(1L, 3L, 2L, 1L, 3L, 3L), .Label = c(A, B, C), class = factor), factor.sample.letters.1.2...6..replace...T.. = structure(c(2L, 2L, 1L, 1L, 2L, 1L), .Label = c(a, b), class = factor), X1.6 = 1:6), .Names = c(factor.sample.LETTERS.1.3...6..replace...T.., factor.sample.letters.1.2...6..replace...T.., X1.6), row.names = c(NA, -6L), class = data.frame) [[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] rms R code
Hi David, I'm always working on a second edition :-) Making more progress now and hope to submit to publisher in April. Frank David Winsemius wrote On Dec 17, 2012, at 7:30 PM, Frank Harrell wrote: In http://biostat.mc.vanderbilt.edu/RmS see the section marked R Code. The zip file there doesn't contain code for all of the book yet; I will be adding code for the rest of the chapters in the next few months. Are you working on a second edition, Frank? Or is one out already and I'm just behind the times? -- David. Frank stephenb wrote I have used the errata from there, but have not found where to download working R code from. Stephen -Original Message- From: Sarah Goslee [mailto: sarah.goslee@ ] Sent: Monday, December 17, 2012 4:22 PM To: Bond, Stephen Cc: r-help@ Subject: Re: [R] rms R code Did you try the website for the book? http://biostat.mc.vanderbilt.edu/wiki/Main/RmS On Mon, Dec 17, 2012 at 4:06 PM, Bond, Stephen lt; Stephen.Bond@ gt; wrote: Greetings, useRs. Does anybody have replication of the examples from the RMS book by Harrell coded in R? I find that most the code does not work and it takes too much time to debug. For example from p.276 age.t - w[,age] f.full - lrm(cvd~scored(rx)+rcs(dtime,5)+age.t+wt.t+pf.t+hx+sbp+ekg.t+sz.t+sg.t+ap.t+bm+hg.t,x=T,y=T) Error in model.frame.default(formula = cvd ~ scored(rx) + rcs(dtime, 5) + : invalid type (list) for variable 'age.t' thanks everybody. Stephen -- Sarah Goslee http://www.functionaldiversity.org __ R-help@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/rms-R-code-tp4653376p4653400.html Sent from the R help mailing list archive at Nabble.com. __ R-help@ 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. David Winsemius Alameda, CA, USA __ R-help@ 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. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/rms-R-code-tp4653376p4653430.html Sent from the R help mailing list archive at Nabble.com. __ 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] averaging X of specific Y (latitude)
You are wrong about my code. The entire excel spreadsheet table should be loaded into R. Save As to a Tab delimited text file and use read.table() to bring the data into R. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: Elaine Kuo [mailto:elaine.kuo...@gmail.com] Sent: Tuesday, December 18, 2012 12:39 AM To: dcarl...@tamu.edu Cc: r-help@r-project.org Subject: Re: [R] averaging X of specific Y (latitude) Hello David, Thank you for the response. I changed the e-mail format to text via gmail setting. 1. the butterfly names You are right that the butterfly names are stored in the original data. However, in your code, it is necessary to input the names for the command structure. The method I used to input is 1. display them in the original excel file, as one column with 11 rows. 2. add commas in a column, right to the name column. 3. copy the columns of butterfly names and commas, then pasting them in the wordpad. 4. copy the wordpad text with butterfly names and commas into your code Since the method sounds tedious, particularly when the number of butterfly names increases over 11, I would like to ask for less time-consuming method to elicit butterfly names as factor. (Maybe using some R command I do not know) 2. Latitude degree Thank you for helping generate the mean of range size per latitudinal degree, using the code:\ Bfly - aggregate(Range~floor(Latitude), dta, mean) Please kindly advise if it is possible to calculate the mean of range size per 5 latitudinal degrees, such as 6-10, 11-15, or 16-20 latitudinal degrees. Thank you again. Elaine dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1, + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1, + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5, + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5, + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78, + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87, + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range, + Latitude), class = data.frame, row.names = c(NA, -11L)) Bfly - aggregate(Range~Species+floor(Latitude), dta, mean) colnames(Bfly) - c(Species, Latitude, Mean) Bfly Species LatitudeMean 1 Butterfly A19 130.50 2 Butterfly A39 1102.38 3 Butterfly A2 10 450.68 4 Butterfly B1 10 820.20 5 Butterfly B2 10 872.20 6 Butterfly B5 12 982.78 7 Butterfly C1 12 720.32 8 Butterfly A4 16 893.34 9 Butterfly B3 16 488.20 10 Butterfly B4 18 620.11 11 Butterfly C2 18 912.20 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 On Tue, Dec 18, 2012 at 11:07 AM, David L Carlson dcarl...@tamu.edu wrote: You should change your email format to text (you keep sending messages in html format). Where are the butterfly names? Are they not in your original data? Create your data.frame from the original data (which presumably has the butterfly names in it already). Then use dput() if you need to email the data to r-help. You cannot compute statistics or graphics from the result of the dput() function. Yes you can produce a barplot. Type ?barplot to get the instructions. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 From: Elaine Kuo [mailto:elaine.kuo...@gmail.com] Sent: Monday, December 17, 2012 6:37 PM To: dcarl...@tamu.edu Cc: r-help@r-project.org Subject: Re: [R] averaging X of specific Y (latitude) Thank you, David. Now I know how to use dput. Two more questions conjured up when running the code: 1. If there are about 500 species of butterflies, please kindly advise if it is possible to input the butterfly names (for .Label) using code, instead of keying in them one by one. 2. Aggregrate command Last time we produced the mean of range sizes. Please kindly advise if it is possible to produce barplot showing the value range, instead of mean. Thank you Elaine code dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1, + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1, + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5, + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5, + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78, + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87, + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range, + Latitude), class = data.frame, row.names = c(NA, -11L)) Bfly -
[R] How to draw frequency domain plot with xts time series data
Hello, I'd like to convert the below time-series data with fft or wavelet related function and plot it. Could you let me know 1. How to convert xts data frame format to list format ? 2. How to plot fft or wavelet diagram ? Here is the data : gt; class(zc) [1] xts zoo gt; str(zc) An âxtsâ object from (10/15/12 09:00:00) to (10/15/12 15:15:00) containing: Data: num [1:366, 1] 252 253 253 253 253 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr Close Indexed by objects of class: [chron,dates,times] TZ: xts Attributes: List of 2 $ tclass: chr [1:3] chron dates times $ tzone : chr head(zc) gt; head(zc) Close (10/15/12 09:00:00) 252.40 (10/15/12 09:01:00) 253.10 (10/15/12 09:02:00) 253.15 (10/15/12 09:03:00) 253.30 (10/15/12 09:04:00) 253.25 (10/15/12 09:05:00) 253.45 Thanks in advance, SK Park [[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] pscore.dist problem when running optmatch
Hello My optmatch package is loaded and otherwise running fine. I get an error after lcds successfully completes logistic regression and I'm trying to obtain a propensity score: pdist - pscore.dist(lcds) Error: could not find function pscore.dist I searched the help files, other online sources, could find no answer for this. Any advice would be greatly appreciated! Thank you Michael Adolph __ 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] R function for computing Simultaneous confidence intervals for multinomial proportions
Dear all, Does someone know an R function implementing the method of Sison and Glaz (1995) (see full ref below) for computing Simultaneous confidence intervals for multinomial proportions? As alternative method, I think to boostrap the mean of each proportion and get in that way confidence interval of the mean. I observed 21 times a response that could be one out of 8 categories (multinomial response). I computed the proportions for every categories. I did it independently 12 times. Hence I have 12 replicats for each proportions. Is boostraping the mean proportion over the 12 replicats for getting the confidence interval is a good idea? I tried (see codes below) and gets some confidence interval quiet large. Actually, according to the boostraped CI, there are no difference in proportions, while a chi2 test confirms that there are. generation of a data set: multinomial réponse variable repeatedly measured sub-c(s1,s2,s3,s4)#subject per-c(p1,P2,p3)#period, RM within subject tim-paste(t,1:21,sep=)#tim, RM within period mydata-expand.grid(tim=tim,per=per,sub=sub) #for simplicity, let's consider that period is not a repeated measure within subject. Hence, we have 12 trials (independent) of 21 observations #random generation of the response variable require(plyr) posl-paste(z,1:8,sep=) mydata$pos-factor(NA,levels=posl) n=nrow(mydata) mydata$pos-replicate(n,sample(posl,1,prob=c(0.05,0.05,0.05,0.4,0.3,0.05,0.05,0.05)))#strong preference for z3 and z4 ##pre-treatment of the above row data, number of time (out of 21) each position was observed mydata2=ddply(mydata,.(sub,per,pos),summarize,nobs=length(pos),.drop=F) mydata2[,1:3]=catcolwise(function(x)as.factor(x))(mydata2) summary(mydata2) # boxplot of frequencies of occpupancy require(ggplot2) mydata2$fobs=mydata2$nobs/21 ggplot(mydata2)+geom_boxplot(aes(pos,fobs)) ###chi2 test nobsT=ddply(mydata,.(pos),summarize,T=length(pos)) nobsT=nobsT[,2] chisq.test(nobsT) ###bootstraping of the mean proportions over the 12 replicats require(boot) maf=function(data,index){o=ddply(data[index,],.(pos),summarize,mmea=mean(fobs),.drop=F);as.vector(o[,2])} bootobj=boot(mydata2,maf,R=,stype=i) confint=ddply(mydata2,.(pos),summarize,mean.prop=mean(fobs)) confint$boot.LOW=-999 confint$boot.UP=-999 for (posi in 1:8){ try({confint$boot.LOW[posi]-boot.ci(bootobj,0.95,index=posi,type=bca)$bca[4]},silent=T) try({confint$boot.UP[posi]-boot.ci(bootobj,0.95,index=posi,type=bca)$bca[5]},silent=T) } ### plotting boostraped CI ggplot(mydata2)+geom_boxplot(aes(pos,fobs))+ geom_errorbar(data=confint,aes(pos,ymin=mean.prop-boot.LOW,ymax=mean.prop+boot.UP),lty=2,width=0.5)+ geom_point(data=confint,aes(pos,mean.prop),shape=24,size=2) References of the CI estimations I would like tu run: Glaz, J. and C.P. Sison. 1999. Simultaneous confidence intervals for multinomial proportions. Journal of Statistical Planning and Inference 82:251-262. Sison, C.P and J. Glaz. 1995. Simultaneous confidence intervals and sample size determination for multinomial proportions. Journal of the American Statistical Association, 90:366-369. Paper available at http://tx.liberal.ntu.edu.tw/~purplewoo/Literature/!Methodology/!Distribution_SampleSize/SimultConfidIntervJASA.pdf I thank you in advance, Respectfully, -- *Pierre THIRIET* Doctorant en écologie marine - Marine Ecology PhD student EA 4228 - ECOMERS - /Ecosystèmes Côtiers Marins et Réponses aux Stress/ Université de Nice - Sophia Antipolis, Faculté des Sciences, Parc Valrose, 06108 Nice Cedex 2, France More about my work and my lab. http://www.unice.fr/ecomers/index.php?option=com_comprofilertask=userProfileuser=101Itemid=111lang=fr Cell: +336 79 44 91 90 Office: +334 92 07 68 33 Skype: pierre.d.thiriet Mail: pierre.thir...@unice.fr Mail(bis): pierre.d.thir...@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] averaging X of specific Y (latitude)
HI Elaine, Regarding the second part of your question, use ?cut() dta$Lat-floor(dta$Latitude) res-aggregate(Range~cut(dta$Lat,breaks=c(6,10,15,20),label=c(6-10,11-15,16-20)),dta,mean) colnames(res)-c(Rangesize,Mean) res # Rangesize Mean #1 6-10 675.1920 #2 11-15 851.5500 #3 16-20 728.4625 A.K. - Original Message - From: Elaine Kuo elaine.kuo...@gmail.com To: dcarl...@tamu.edu Cc: r-help@r-project.org Sent: Tuesday, December 18, 2012 1:39 AM Subject: Re: [R] averaging X of specific Y (latitude) Hello David, Thank you for the response. I changed the e-mail format to text via gmail setting. 1. the butterfly names You are right that the butterfly names are stored in the original data. However, in your code, it is necessary to input the names for the command structure. The method I used to input is 1. display them in the original excel file, as one column with 11 rows. 2. add commas in a column, right to the name column. 3. copy the columns of butterfly names and commas, then pasting them in the wordpad. 4. copy the wordpad text with butterfly names and commas into your code Since the method sounds tedious, particularly when the number of butterfly names increases over 11, I would like to ask for less time-consuming method to elicit butterfly names as factor. (Maybe using some R command I do not know) 2. Latitude degree Thank you for helping generate the mean of range size per latitudinal degree, using the code:\ Bfly - aggregate(Range~floor(Latitude), dta, mean) Please kindly advise if it is possible to calculate the mean of range size per 5 latitudinal degrees, such as 6-10, 11-15, or 16-20 latitudinal degrees. Thank you again. Elaine dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1, + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1, + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5, + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5, + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78, + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87, + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range, + Latitude), class = data.frame, row.names = c(NA, -11L)) Bfly - aggregate(Range~Species+floor(Latitude), dta, mean) colnames(Bfly) - c(Species, Latitude, Mean) Bfly Species Latitude Mean 1 Butterfly A1 9 130.50 2 Butterfly A3 9 1102.38 3 Butterfly A2 10 450.68 4 Butterfly B1 10 820.20 5 Butterfly B2 10 872.20 6 Butterfly B5 12 982.78 7 Butterfly C1 12 720.32 8 Butterfly A4 16 893.34 9 Butterfly B3 16 488.20 10 Butterfly B4 18 620.11 11 Butterfly C2 18 912.20 -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 On Tue, Dec 18, 2012 at 11:07 AM, David L Carlson dcarl...@tamu.edu wrote: You should change your email format to text (you keep sending messages in html format). Where are the butterfly names? Are they not in your original data? Create your data.frame from the original data (which presumably has the butterfly names in it already). Then use dput() if you need to email the data to r-help. You cannot compute statistics or graphics from the result of the dput() function. Yes you can produce a barplot. Type ?barplot to get the instructions. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 From: Elaine Kuo [mailto:elaine.kuo...@gmail.com] Sent: Monday, December 17, 2012 6:37 PM To: dcarl...@tamu.edu Cc: r-help@r-project.org Subject: Re: [R] averaging X of specific Y (latitude) Thank you, David. Now I know how to use dput. Two more questions conjured up when running the code: 1. If there are about 500 species of butterflies, please kindly advise if it is possible to input the butterfly names (for .Label) using code, instead of keying in them one by one. 2. Aggregrate command Last time we produced the mean of range sizes. Please kindly advise if it is possible to produce barplot showing the value range, instead of mean. Thank you Elaine code dta - structure(list(Species = structure(1:11, .Label = c(Butterfly A1, + Butterfly A2, Butterfly A3, Butterfly A4, Butterfly B1, + Butterfly B2, Butterfly B3, Butterfly B4, Butterfly B5, + Butterfly C1, Butterfly C2), class = factor), Range = c(130.5, + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78, + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87, + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c(Species, Range, + Latitude), class = data.frame, row.names = c(NA, -11L)) Bfly - aggregate(Range~Species+floor(Latitude), dta, mean) colnames(Bfly) - c(Species, Latitude, Mean) Bfly Species Latitude Mean 1 Butterfly A1 9
Re: [R] Summarizing elements for a data.frame
Hi, You could also use ?xtabs() dat1-structure(list(Col1 = structure(c(1L, 3L, 2L, 1L, 3L, 3L, 1L), .Label = c(A, B, C), class = factor), Col2 = structure(c(2L, 2L, 1L, 1L, 2L, 1L, 2L), .Label = c(a, b), class = factor), Col3 = c(1, 2, 3, 4, 5, 6, 2)), .Names = c(Col1, Col2, Col3), row.names = c(NA, 7L), class = data.frame) xtabs(Col3~Col1+Col2,data=dat1) # Col2 #Col1 a b # A 4 3 # B 3 0 # C 6 7 tapply(dat1[,3],list(dat1[,1],dat1[,2]),sum) # a b #A 4 3 #B 3 NA #C 6 7 A.K. - Original Message - From: Christofer Bogaso bogaso.christo...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Tuesday, December 18, 2012 9:36 AM Subject: [R] Summarizing elements for a data.frame Hello again, let say we have following data: Dat1 - structure(list(factor.sample.LETTERS.1.3...6..replace...T.. = structure(c(1L, 3L, 2L, 1L, 3L, 3L), .Label = c(A, B, C), class = factor), factor.sample.letters.1.2...6..replace...T.. = structure(c(2L, 2L, 1L, 1L, 2L, 1L), .Label = c(a, b), class = factor), X1.6 = 1:6), .Names = c(factor.sample.LETTERS.1.3...6..replace...T.., factor.sample.letters.1.2...6..replace...T.., X1.6), row.names = c(NA, -6L), class = data.frame) Out of this data.frame, I want to create a Table with rows coming from 1st column of Dat1 and columns are coming from 2nd column of Dat1 and each entry will be the sum for 3rd column of Dat1, i.e. the element for (1,1) will be sum for all element in 3rd column corresponding to (A, a) and so on. I tried with table() however could not achieve what I wanted. Can somebody give me some pointer? Thanks and regards, __ 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] Set a zero at minimum row by group
Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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] xtable with psych objects
Hello: I s there a way to use xtable with objects from the psych package, particularly principal()? Is there a difference between princomp and principal? xtable seems to play better with princomp. Thank you. Yours, Simon Kiss * Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada N3T 2C9 __ 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] Set a zero at minimum row by group
There may be more efficient ways, but here's one: x_new - rep(0,nrow(df)) x_new - ifelse(df$T==min(T),0,1) Regards, José -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carlos Nasher Sent: 18 December 2012 14:10 To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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. Wrap Up and Run 10k is back! Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by signing up now: http://www.ageuk.org.uk/10k Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds | Tatton Park, Cheshire | Southampton | Coventry Age UK Improving later life http://www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ 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] subset handling
Dear Rui, thankyou very much. it really worked. extremly sorry for telling you a bit late as i was on the move. eliza Date: Tue, 18 Dec 2012 00:44:44 + From: ruipbarra...@sapo.pt To: eliza_bo...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] subset handling Hello, You could have attached the output of dput(), it's much, much better. I have tried the following and it works. sp - lapply(split(agg, agg$st), function(x) x[order(x$year, x$month), ]) sp - lapply(sp, function(x) data.frame(year = x$year + x$month/12, Population = x$Population)) # Plot it plot(agg$year, agg$Population, type = n) lapply(seq_along(sp), function(i) lines(sp[[i]]$year, sp[[i]]$Population, col = i)) Hope this helps, Rui Barradas Em 17-12-2012 23:37, eliza botto escreveu: Dear Rui and UseRs,[a text file has also been attached, in case the format of my email is difficult to get]I am extremely sorry that I am bothering you once again, but Ill have to get to the bottom of it. The following command sp - lapply(split(agg, agg$st), function(x) x[order(x$year, x$month), ]) gave me an output with monthly mean of population(as under). i am not able to apply plot command on all these sublists(if you like), so that i may have curves, on the same single plot, with population on y and years on x. you can also see that the year span for each city is different. kindly help me on it head(sp)$TA st year month Population833 TA 2004 1 2.247334532216 TA 2004 2 2.034244993599 TA 2004 3 1.899890504982 TA 2004 4 6.052611006365 TA 2004 5 10.615058437748 TA 2004 6 0.169251019131 TA 2004 7 0.2465087910514 TA 2004 8 1.5664566411897 TA 2004 9 0.1406784513280 TA 200410 2.7955931914663 TA 200411 5.9957331616046 TA 200412 3.71105320893 TA 2005 1 2.098415862276 TA 2005 2 1.204160663659 TA 2005 3 1.322819365042 TA 2005 4 4.945368026425 TA 2005 5 2.801564867808 TA 2005 6 1.074420609191 TA 2005 7 0.8215437210574 TA 2005 8 0.9716208511957 TA 2005 9 2.3597912713340 TA 200510 1.4188611714723 TA 200511 1.0923996616106 TA 200512 1.16220849961 TA 2006 1 0.616895432344 TA 2006 2 2.722854713727 TA 2006 3 1.774377945110 TA 2006 4 2.074901626493 TA 2006 5 1.769752057876 TA 2006 6 0.33803717 9259 TA 2006 7 0.3326822110642 TA 2006 8 0.7861863912025 TA 2006 9 5.3897497313408 TA 200610 1.8968963414791 TA 200611 0.6761301016174 TA 200612 6.937671661037 TA 2007 1 1.370728562420 TA 2007 2 0.810231753803 TA 2007 3 0.740445765186 TA 2007 4 0.272355546569 TA 2007 5 1.111914807952 TA 2007 6 5.546398019335 TA 2007 7 0.3878977110718 TA 2007 8 2.0132851912101 TA 2007 9 0.3499476713484 TA 200710 0.0620175614867 TA 200711 1.2077858516250 TA 200712 0.401812311107 TA 2008 1 2.362968882490 TA 2008 2 1.499176343873 TA 2008 3 0.348776885256 TA 2008 4 5.125779446639 TA 2008 5 9.109894968022 TA 2008 6 7.642119919405 TA 2008 7 4.5458325710788 TA 2008 8 2.1524258712171 TA 2008 9 3.4034146913554 TA 200810 0.9428364214937 TA 200811 9.7961244216320 TA 200812 17.286549731197 TA 2009 1 5.219552552580 TA 2009 2 13.221212883963 TA 2009 3 7.395581695346 TA 2009 4 19.673796716729 TA 2009 5 6.824322768112 TA 2009 6 3.640100819495 TA 2009 7 1.0856853210878 TA 2009 8 0.6736243612261 TA 2009 9 2.3143062613644 TA 200910 1.3568127015027 TA 200911 3.1974017316410 TA 200912 8.095355091287 TA 2010 1 4.514000372670 TA 2010 2 4.553753744053 TA 2010 3 5.406310075436 TA 2010 4 6.432289056819 TA 2010 5 18.353004228202 TA 2010 6 4.948599699585 TA 2010 7 1.1451292410968 TA 2010 8 2.9871427212351 TA 2010 9 1.4842024013734 TA 201010 3.1262495515117 TA 201011 15.7069261816500 TA 201012 9.14136881 $SA st year month discharge750 SA 2002 1 1.2224582133 SA 2002 2 11.4975843516 SA 2002 3 10.0225344899 SA 2002 4 2.9534806282 SA 2002 5 34.5473237665 SA 2002 6 9.4179869048 SA 2002 7 9.05625010431 SA 2002 8 14.76690411814 SA 2002 9 18.44218213197 SA 2002 10 9.98924914580 SA 200211 40.51801315963 SA 200212 16.090995777 SA 2003 1 8.7098202160 SA 2003 2 5.4703533543 SA 2003 3 4.0399514926 SA 2003 4 1.3304636309 SA 2003 5 1.6063207692 SA 2003 6 1.3598099075 SA 2003 7 1.87694210458 SA 2003 8 2.07546711841 SA 2003 9 5.36862913224 SA 200310 3.93717214607 SA 200311 14.11299915990 SA 200312 20.200956834 SA 2004 1 14.4805562217 SA 2004 2 13.4225393600 SA 2004 3 13.0754914983 SA 2004 4 13.1569846366 SA 2004 5 16.6770507749 SA 2004 6
Re: [R] xtable with psych objects
On Dec 18, 2012, at 9:24 AM, Simon Kiss sjk...@gmail.com wrote: Hello: I s there a way to use xtable with objects from the psych package, particularly principal()? Is there a difference between princomp and principal? xtable seems to play better with princomp. Thank you. Yours, Simon Kiss I have not used the psych package, so not sure about the differences in the function or what type of object it returns. xtable has support for: methods(xtable) [1] xtable.anova* xtable.aov* [3] xtable.aovlist* xtable.coxph* [5] xtable.data.frame* xtable.glm* [7] xtable.lm* xtable.matrix* [9] xtable.prcomp* xtable.summary.aov* [11] xtable.summary.aovlist* xtable.summary.glm* [13] xtable.summary.lm* xtable.summary.prcomp* [15] xtable.table* xtable.ts* [17] xtable.zoo* So it would seem that there is a method for 'prcomp' class objects, as opposed to 'princomp', albeit, there are similarities. Typically, if there is not a built-in method for a given class, you would need to create an object of a class that is supported, containing the results that you want to output. So that could perhaps be either a matrix or a data frame, which ever is more suitable for your case. Regards, Marc Schwartz __ 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] Summarizing elements for a data.frame
And yet another way. library(reshape2) names(Dat1) - c(big,small,nums) dcast(Dat1 , big ~ small, sum) John Kane Kingston ON Canada -Original Message- From: bogaso.christo...@gmail.com Sent: Tue, 18 Dec 2012 20:06:42 +0530 To: r-help@r-project.org Subject: [R] Summarizing elements for a data.frame Hello again, let say we have following data: Dat1 - structure(list(factor.sample.LETTERS.1.3...6..replace...T.. = structure(c(1L, 3L, 2L, 1L, 3L, 3L), .Label = c(A, B, C), class = factor), factor.sample.letters.1.2...6..replace...T.. = structure(c(2L, 2L, 1L, 1L, 2L, 1L), .Label = c(a, b), class = factor), X1.6 = 1:6), .Names = c(factor.sample.LETTERS.1.3...6..replace...T.., factor.sample.letters.1.2...6..replace...T.., X1.6), row.names = c(NA, -6L), class = data.frame) Out of this data.frame, I want to create a Table with rows coming from 1st column of Dat1 and columns are coming from 2nd column of Dat1 and each entry will be the sum for 3rd column of Dat1, i.e. the element for (1,1) will be sum for all element in 3rd column corresponding to (A, a) and so on. I tried with table() however could not achieve what I wanted. Can somebody give me some pointer? Thanks and regards, __ 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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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] Set a zero at minimum row by group
You should show what you tried with aggregate and tapply. You could use ave(): wm - as.logical(ave(df$T, df$ID, FUN=function(x)x==min(x))) df$x_new - df$x df$x_new[wm] - 0 df ID T x x_new 1 1 1 1 0 2 1 2 1 1 3 1 3 1 1 4 2 1 1 0 5 2 4 1 1 6 3 3 1 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 (The as.logical is there because ave() coerces the logical output of FUN to the type of df$T, numeric, and we need to convert it back to logical.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carlos Nasher Sent: Tuesday, December 18, 2012 6:10 AM To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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.
Re: [R] How to draw frequency domain plot with xts time series data
Cross-posted on Stackoverflow: http://stackoverflow.com/q/13935782/271616 -- Joshua Ulrich | about.me/joshuaulrich FOSS Trading | www.fosstrading.com On Tue, Dec 18, 2012 at 7:59 AM, 박상규 birdfir...@naver.com wrote: Hello, I'd like to convert the below time-series data with fft or wavelet related function and plot it. Could you let me know 1. How to convert xts data frame format to list format ? 2. How to plot fft or wavelet diagram ? Here is the data : gt; class(zc) [1] xts zoo gt; str(zc) An ‘xts’ object from (10/15/12 09:00:00) to (10/15/12 15:15:00) containing: Data: num [1:366, 1] 252 253 253 253 253 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr Close Indexed by objects of class: [chron,dates,times] TZ: xts Attributes: List of 2 $ tclass: chr [1:3] chron dates times $ tzone : chr head(zc) gt; head(zc) Close (10/15/12 09:00:00) 252.40 (10/15/12 09:01:00) 253.10 (10/15/12 09:02:00) 253.15 (10/15/12 09:03:00) 253.30 (10/15/12 09:04:00) 253.25 (10/15/12 09:05:00) 253.45 Thanks in advance, SK Park [[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] how to get a value from a list (using paste function)?
Dear my R friends, I want to get a number from a list using paste function. In my example, lambda.rule - lambda.1se cvtest is a list (result from cv.glmnet) and cvtest$lambda.1se [1] 1.308973 I want to call the value using paste function. I used get function but there was an error. test - get(paste(cvtest$,lambda.rule, sep=)) Error in get(paste(cvtest$, lambda.rule, sep = )) : object 'cvtest$lambda.1se' not found Do you guys know how to solve this issue? Thank you so much in advance and merry Christmas! Soyeon __ 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] Breaking out of multiple loops
Hey all, I'm currently working through the problems at Project Euler -- this question came up while working on Problem 9 (http://projecteuler.net/problem=9): A Pythagorean triplet is a set of three natural numbers, a b c, for which, a^2 + b^2 = c^2. For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. Not too hard: n=1000 for(i in 1:floor(n/3)) for(j in (i+1):floor(n/2-i/2)) if(i^2+j^2==(n-i-j)^2) {print(i*j*(n-i-j)); stop()} I could just let the for loops finish looping after it finds the answer, and it would still run in under a second, but the goal of Project Euler is sort of to see how efficiently (and quickly) you can solve these problems, so in that spirit I would like to break out of the for loops early once the answer is found -- hence the call to stop(). However, this seems improper, as it throws up an error. Is there a way to exit out of both for loops with a call to break or similar that would not throw errors (or is it fine the way I've coded it)? (I realize I could put an if(i^2+j^2==(n-i-j)^2) break statement in the outer loop, but again that's inefficient, as it's checking that conditional hundreds of times.) So is there a way to cleanly break out of multiple loops? Thanks, -bryan __ 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] Changing Variable Names In VCD
Hello: What is the most efficient way to change the plotted variable names in mosaic plots in the vcd package? Should one do a separate contingency table first, change the dimension names there and then pass that to mosaic? Or is there a way to do it simply within mosaic. I was thinking something like: mosaic(~var1+var2, labelling_args=list(varnames=c('newvar1', 'newvar2')) Simon Kiss * Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada __ 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] Changing Variable Names In VCD
Simon: What is the most efficient way to change the plotted variable names in mosaic plots in the vcd package? Should one do a separate contingency table first, change the dimension names there and then pass that to mosaic? Or is there a way to do it simply within mosaic. I was thinking something like: mosaic(~var1+var2, labelling_args=list(varnames=c('newvar1', 'newvar2')) Almost. The default labeling function is labeling_border which does take a varnames argument but this should be logical (should labels be drawn or not?). The argument set_varnames can be used to set the varnames to different strings, e.g., mosaic(~ Gender + Admit, data = UCBAdmissions, labeling_args = list(set_varnames = list(Gender = Foo, Admit = Bar))) I hope this is what you're looking for. Best, Z Simon Kiss * Simon J. Kiss, PhD Assistant Professor, Wilfrid Laurier University 73 George Street Brantford, Ontario, Canada __ 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] multi dimensional optim problem
I am attempting to use optim to solve a neural network problem. I would like to optimize coefficients that are currently stored in a matrix Y=270 x 1 X= 27- x 14 b1= 10x14 b2= 11x1 V= 10 x 14 set of prior variances. I have the following function: posterior.mode1=function(y,X,b_0,b2,V) { log.like=function(b1) { a_g=compute(b1) z_g=tanh(a_g); z_g=cbind(1,z_g) p=softmax(z_g%*%b2); a=sum(y*log(p)+(1-y)*log(1-p)); return(a); } compute=function(b1) { a_g=NULL; for(i in 1:nrow(b1)){ a_g=cbind(a_g,X%*%b1[i,]) } return(a_g); } log.posterior=function(b1) { -log.like(b1)+1/2*t(as.vector(b1))%*%diag(as.vector(V))%*%as.vector(b1) } a=optim(b_0,log.posterior,method=CG,hessian=TRUE) return(a); } When I run posterior.mode1(y,X,b1,b2,b1) I get the following error Error in 1:nrow(b1) : argument of length 0 Any comments would be very helpful Thanks [[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] Set a zero at minimum row by group
Hi, You could also use: df$x_new-unlist(lapply(split(df,df$ID),function(x) as.numeric(min(x[,2])!=x[,2]))) df # ID T x x_new #1 1 1 1 0 #2 1 2 1 1 #3 1 3 1 1 #4 2 1 1 0 #5 2 4 1 1 #6 3 3 1 0 #7 3 5 1 1 #8 3 6 1 1 #9 3 8 1 1 A.K. - Original Message - From: Jose Iparraguirre jose.iparragui...@ageuk.org.uk To: Carlos Nasher carlos.nas...@googlemail.com; r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, December 18, 2012 11:32 AM Subject: Re: [R] Set a zero at minimum row by group There may be more efficient ways, but here's one: x_new - rep(0,nrow(df)) x_new - ifelse(df$T==min(T),0,1) Regards, José -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carlos Nasher Sent: 18 December 2012 14:10 To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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. Wrap Up and Run 10k is back! Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by signing up now: http://www.ageuk.org.uk/10k Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds | Tatton Park, Cheshire | Southampton | Coventry Age UK Improving later life http://www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ 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] how to get a value from a list (using paste function)?
HI, It guess ?get() does not work with $ elements. x1 - list(a=c(1,2), b = c(2,4), c=c(4,5,6)) #this works get(paste(x,1,sep=))[a] #$a #[1] 1 2 #or get(paste(x,1,sep=))[[2]] #[1] 2 4 A.K. - Original Message - From: Soyeon Kim yunni0...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Tuesday, December 18, 2012 12:34 PM Subject: [R] how to get a value from a list (using paste function)? Dear my R friends, I want to get a number from a list using paste function. In my example, lambda.rule - lambda.1se cvtest is a list (result from cv.glmnet) and cvtest$lambda.1se [1] 1.308973 I want to call the value using paste function. I used get function but there was an error. test - get(paste(cvtest$,lambda.rule, sep=)) Error in get(paste(cvtest$, lambda.rule, sep = )) : object 'cvtest$lambda.1se' not found Do you guys know how to solve this issue? Thank you so much in advance and merry Christmas! Soyeon __ 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] Set a zero at minimum row by group
Hi, I get the results from your method: x_new #[1] 0 1 1 0 1 1 1 1 1 I guess there should be three zeros, as there are three IDs. A.K. - Original Message - From: Jose Iparraguirre jose.iparragui...@ageuk.org.uk To: Carlos Nasher carlos.nas...@googlemail.com; r-help@r-project.org r-help@r-project.org Cc: Sent: Tuesday, December 18, 2012 11:32 AM Subject: Re: [R] Set a zero at minimum row by group There may be more efficient ways, but here's one: x_new - rep(0,nrow(df)) x_new - ifelse(df$T==min(T),0,1) Regards, José -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Carlos Nasher Sent: 18 December 2012 14:10 To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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. Wrap Up and Run 10k is back! Also, new for 2013 – 2km intergenerational walks at selected venues. So recruit a buddy, dust off the trainers and beat the winter blues by signing up now: http://www.ageuk.org.uk/10k Milton Keynes | Oxford | Sheffield | Crystal Palace | Exeter | Harewood House, Leeds | Tatton Park, Cheshire | Southampton | Coventry Age UK Improving later life http://www.ageuk.org.uk --- Age UK is a registered charity and company limited by guarantee, (registered charity number 1128267, registered company number 6825798). Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA. For the purposes of promoting Age UK Insurance, Age UK is an Appointed Representative of Age UK Enterprises Limited, Age UK is an Introducer Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth Access for the purposes of introducing potential annuity and health cash plans customers respectively. Age UK Enterprises Limited, JLT Benefit Solutions Limited and Simplyhealth Access are all authorised and regulated by the Financial Services Authority. -- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you receive a message in error, please advise the sender and delete immediately. Except where this email is sent in the usual course of our business, any opinions expressed in this email are those of the author and do not necessarily reflect the opinions of Age UK or its subsidiaries and associated companies. Age UK monitors all e-mail transmissions passing through its network and may block or modify mails which are deemed to be unsuitable. Age Concern England (charity number 261794) and Help the Aged (charity number 272786) and their trading and other associated companies merged on 1st April 2009. Together they have formed the Age UK Group, dedicated to improving the lives of people in later life. The three national Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help the Aged in these nations to form three registered charities: Age Scotland, Age NI, Age Cymru. __ 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] how to get a value from a list (using paste function)?
# use the mtcars data frame as your starting list. save it to x x - as.list( mtcars ) # just print one column, by hand. x$wt # ..dynamically choose the column you want colname - 'wt' # this breaks get( paste( 'x$' , colname , sep = ) ) # this works, but doesn't do what you want, since it's not dynamic get( 'x' )$wt # why not access the list dynamically without paste() or get() ? ;) x[ colname ] [[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] how to get a value from a list (using paste function)?
Soyeon- A possible solution: get(lambda.rule,envir=list2env(cvtest)) On Tue, Dec 18, 2012 at 12:34 PM, Soyeon Kim yunni0...@gmail.com wrote: Dear my R friends, I want to get a number from a list using paste function. In my example, lambda.rule - lambda.1se cvtest is a list (result from cv.glmnet) and cvtest$lambda.1se [1] 1.308973 I want to call the value using paste function. I used get function but there was an error. test - get(paste(cvtest$,lambda.rule, sep=)) Error in get(paste(cvtest$, lambda.rule, sep = )) : object 'cvtest$lambda.1se' not found Do you guys know how to solve this issue? Thank you so much in advance and merry Christmas! Soyeon __ 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] Problem installing package caret
David: More specifically: library(forecast)Loading required package: parallelLoading required package: tseries tseries version: 0.10-30 tseries is a package for time series analysis and computational finance. See library(help=tseries) for details. Attaching package: tseries The following object(s) are masked from package:chron: is.weekend Loading required package: fracdiffLoading required package: colorspaceLoading required package: nnetLoading required package: caretError: package caret could not be loadedIn addition: Warning message:In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called caret library(caret)Error in library(caret) : there is no package called caret On Wed, Dec 12, 2012 at 10:01 AM, David Winsemius dwinsem...@comcast.netwrote: On Dec 12, 2012, at 7:32 AM, John Kerpel wrote: Folks: I keep getting the following error message (I'm on Windows 7, R-2.15.2, and tried a reboot...). Thx! Actually it's only a warning. Those are not the same in R. John install.packages(caret)**Installing package(s) into C:/Program Files/R/R-2.15.2/library (as lib is unspecified)trying URL 'http://streaming.stat.**iastate.edu/CRAN/bin/windows/** contrib/2.15/caret_5.15-045.**zip'Contenthttp://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/caret_5.15-045.zip'Content type 'application/zip' length 3478831 bytes (3.3 Mb)opened URLdownloaded 3.3 Mb package caret successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation C:\Program Files\R\R-2.15.2\library\**file1628360a1dc0\caret to C:\Program Files\R\R-2.15.2\library\**caret The downloaded binary packages are in C:\Users\AppData\Local\Temp\**RtmpK2YZCa\downloaded_packages [[alternative HTML version deleted]] It suggests that you might need to consult your system documentation regarding how to use permissions. Are you able to load package:caret? -- David Winsemius, MD Alameda, CA, USA [[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 installing package caret
Uwe: More specifically: library(forecast)Loading required package: parallelLoading required package: tseries tseries version: 0.10-30 tseries is a package for time series analysis and computational finance. See library(help=tseries) for details. Attaching package: tseries The following object(s) are masked from package:chron: is.weekend Loading required package: fracdiffLoading required package: colorspaceLoading required package: nnetLoading required package: caretError: package caret could not be loadedIn addition: Warning message:In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called caret library(caret)Error in library(caret) : there is no package called caret So the package won't load as a part of package forecast, nor will it load on its own after I download it individually. Thanks for the help. J On Wed, Dec 12, 2012 at 10:03 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 12.12.2012 16:32, John Kerpel wrote: Folks: I keep getting the following error message (I'm on Windows 7, R-2.15.2, and tried a reboot...). Thx! Either you do not have write permission on that directory or you have the package loaded already, Uwe Ligges John install.packages(caret)**Installing package(s) into C:/Program Files/R/R-2.15.2/library (as lib is unspecified)trying URL 'http://streaming.stat.**iastate.edu/CRAN/bin/windows/** contrib/2.15/caret_5.15-045.**zip'Contenthttp://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/caret_5.15-045.zip'Content type 'application/zip' length 3478831 bytes (3.3 Mb)opened URLdownloaded 3.3 Mb package caret successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation C:\Program Files\R\R-2.15.2\library\**file1628360a1dc0\caret to C:\Program Files\R\R-2.15.2\library\**caret The downloaded binary packages are in C:\Users\AppData\Local\Temp\**RtmpK2YZCa\downloaded_packages [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Problem installing package caret
Uwe: Well, a simple re-install did the trick apparently: install.packages(forecast)Installing package(s) into C:/Program Files/R/R-2.15.2/library (as lib is unspecified)also installing the dependency caret trying URL 'http://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/caret_5.15-045.zip'Content type 'application/zip' length 3478831 bytes (3.3 Mb)opened URLdownloaded 3.3 Mb trying URL 'http://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/forecast_4.00.zip'Content type 'application/zip' length 1090858 bytes (1.0 Mb)opened URLdownloaded 1.0 Mb package caret successfully unpacked and MD5 sums checked package forecast successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\AppData\Local\Temp\RtmpK2YZCa\downloaded_packages library(forecast)Loading required package: caretLoading required package: latticeLoading required package: reshapeLoading required package: plyr Attaching package: reshape The following object(s) are masked from package:plyr: rename, round_any Loading required package: clusterLoading required package: foreachforeach: simple, scalable parallel programming from Revolution Analytics Use Revolution R for scalability, fault tolerance and more.http://www.revolutionanalytics.com Attaching package: foreach The following object(s) are masked from package:chron: times This is forecast 4.00 On Tue, Dec 18, 2012 at 1:48 PM, John Kerpel john.kerp...@gmail.com wrote: Uwe: More specifically: library(forecast)Loading required package: parallelLoading required package: tseries tseries version: 0.10-30 tseries is a package for time series analysis and computational finance. See library(help=tseries) for details. Attaching package: tseries The following object(s) are masked from package:chron: is.weekend Loading required package: fracdiffLoading required package: colorspaceLoading required package: nnetLoading required package: caretError: package caret could not be loadedIn addition: Warning message:In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called caret library(caret)Error in library(caret) : there is no package called caret So the package won't load as a part of package forecast, nor will it load on its own after I download it individually. Thanks for the help. J On Wed, Dec 12, 2012 at 10:03 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 12.12.2012 16:32, John Kerpel wrote: Folks: I keep getting the following error message (I'm on Windows 7, R-2.15.2, and tried a reboot...). Thx! Either you do not have write permission on that directory or you have the package loaded already, Uwe Ligges John install.packages(caret)**Installing package(s) into C:/Program Files/R/R-2.15.2/library (as lib is unspecified)trying URL 'http://streaming.stat.**iastate.edu/CRAN/bin/windows/** contrib/2.15/caret_5.15-045.**zip'Contenthttp://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/caret_5.15-045.zip'Content type 'application/zip' length 3478831 bytes (3.3 Mb)opened URLdownloaded 3.3 Mb package caret successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation C:\Program Files\R\R-2.15.2\library\**file1628360a1dc0\caret to C:\Program Files\R\R-2.15.2\library\**caret The downloaded binary packages are in C:\Users\AppData\Local\Temp\**RtmpK2YZCa\downloaded_packages [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Problem installing package caret
Thanks for letting me know, Uwe On 18.12.2012 21:00, John Kerpel wrote: Uwe: Well, a simple re-install did the trick apparently: install.packages(forecast)Installing package(s) into ‘C:/Program Files/R/R-2.15.2/library’ (as ‘lib’ is unspecified)also installing the dependency ‘caret’ trying URL 'http://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/caret_5.15-045.zip'Content type 'application/zip' length 3478831 bytes (3.3 Mb)opened URLdownloaded 3.3 Mb trying URL 'http://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/forecast_4.00.zip'Content type 'application/zip' length 1090858 bytes (1.0 Mb)opened URLdownloaded 1.0 Mb package ‘caret’ successfully unpacked and MD5 sums checked package ‘forecast’ successfully unpacked and MD5 sums checked The downloaded binary packages are in C:\Users\AppData\Local\Temp\RtmpK2YZCa\downloaded_packages library(forecast)Loading required package: caretLoading required package: latticeLoading required package: reshapeLoading required package: plyr Attaching package: ‘reshape’ The following object(s) are masked from ‘package:plyr’: rename, round_any Loading required package: clusterLoading required package: foreachforeach: simple, scalable parallel programming from Revolution Analytics Use Revolution R for scalability, fault tolerance and more.http://www.revolutionanalytics.com Attaching package: ‘foreach’ The following object(s) are masked from ‘package:chron’: times This is forecast 4.00 On Tue, Dec 18, 2012 at 1:48 PM, John Kerpel john.kerp...@gmail.com wrote: Uwe: More specifically: library(forecast)Loading required package: parallelLoading required package: tseries ‘tseries’ version: 0.10-30 ‘tseries’ is a package for time series analysis and computational finance. See ‘library(help=tseries)’ for details. Attaching package: ‘tseries’ The following object(s) are masked from ‘package:chron’: is.weekend Loading required package: fracdiffLoading required package: colorspaceLoading required package: nnetLoading required package: caretError: package ‘caret’ could not be loadedIn addition: Warning message:In library(pkg, character.only = TRUE, logical.return = TRUE, lib.loc = lib.loc) : there is no package called ‘caret’ library(caret)Error in library(caret) : there is no package called ‘caret’ So the package won't load as a part of package forecast, nor will it load on its own after I download it individually. Thanks for the help. J On Wed, Dec 12, 2012 at 10:03 AM, Uwe Ligges lig...@statistik.tu-dortmund.de wrote: On 12.12.2012 16:32, John Kerpel wrote: Folks: I keep getting the following error message (I'm on Windows 7, R-2.15.2, and tried a reboot...). Thx! Either you do not have write permission on that directory or you have the package loaded already, Uwe Ligges John install.packages(caret)**Installing package(s) into ‘C:/Program Files/R/R-2.15.2/library’ (as ‘lib’ is unspecified)trying URL 'http://streaming.stat.**iastate.edu/CRAN/bin/windows/** contrib/2.15/caret_5.15-045.**zip'Contenthttp://streaming.stat.iastate.edu/CRAN/bin/windows/contrib/2.15/caret_5.15-045.zip'Content type 'application/zip' length 3478831 bytes (3.3 Mb)opened URLdownloaded 3.3 Mb package ‘caret’ successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation ‘C:\Program Files\R\R-2.15.2\library\**file1628360a1dc0\caret’ to ‘C:\Program Files\R\R-2.15.2\library\**caret’ The downloaded binary packages are in C:\Users\AppData\Local\Temp\**RtmpK2YZCa\downloaded_packages [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Fwd: I need help with an R function! Thx!
Hi! I am doing a course about the R software and I have a couple of doubts. In one of the tasks we were asigned, we have to perform a function that simulates a bus' trip with 25 stops. In each of those stops, between 0 and 6 people can go on board. And when the total of passengers reaches 44, no more people can go on board. stops - 25 passengers - 0 register - numeric(25) bus - function(register,stops,passengers) { register[1] - passengers for (i in 1:stops) { passengers - passengers + sample(0:6,1) register[i] - passengers } # If the bus isn't full: if (passengers = 44) { # Adjustment if it reaches 44 passenger, before the 25th stop: register[i:stops] - 44 cat('Full bus!\n') # Warning message... break } else { # If the loop doesn't stop, a new register must be added: register[i] - passengers } # Para ir viendo cuánto hay: cat('Stop', i, 'hay', passengers, 'passenger\n') } plot(register, xlab='Stop', ylab='No. of passengers') The parts of the script that are marked in sky blue, are the ones that we have to fill up, so on of those should be my mistake. I would be very glad, if anyone can detect my error, as I have been many days stuck on this part and my deadline is tomorrow. Thx a lot in advance to everyone. Wanda BTW: Sorry for my English! My native language is Spanish! :) [[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 line does not show on scatterplot
Hello, I have done a scatterplot and now would like to add its regression line but it does not show. Below, the code I have used. lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) abline(lm3) I have been able to do the complete operation using the software STATISTICA but it would be great to do it with R. If you require more details please get in touch. Thanks a lot! Bea [[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] Regression line does not show on scatterplot
You swapped the x and y variables in the plot command. lm(y~ x) but plot(x, y) On Tue, Dec 18, 2012 at 3:09 PM, Beatriz González Domínguez harimagua...@gmail.com wrote: Hello, I have done a scatterplot and now would like to add its regression line but it does not show. Below, the code I have used. lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) abline(lm3) I have been able to do the complete operation using the software STATISTICA but it would be great to do it with R. If you require more details please get in touch. Thanks a lot! Bea -- 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.
Re: [R] Regression line does not show on scatterplot
On 18-Dec-2012 20:09:36 Beatriz González Domínguez wrote: Hello, I have done a scatterplot and now would like to add its regression line but it does not show. Below, the code I have used. lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) abline(lm3) I have been able to do the complete operation using the software STATISTICA but it would be great to do it with R. If you require more details please get in touch. Thanks a lot! Bea By the look of things you have either the regression or the plot the wrong way round. I suspect it is the regression. So try: Either: ##lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) lm3 - lm(data$S_pH_KCl2.5_BCx_per~data$B_OleicoPF_BCx) plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) abline(lm3) Or: lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) ##plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) plot(data$S_pH_KCl2.5_BCx_per, data$B_OleicoPF_BCx) abline(lm3) The point is that in lm(V~U) the variable U is taken as corresponding the the x-axis (independent variable), and the variable V to the y-axis (dependent variable). Similarly for plot(U,V). So, for lm3 - lm(V~U), abline(lm3) will plot the fitted V-values (y-axis) against the U-values (x-axis). Your original code was equivalent to: lm3 - lm(V~U) plot(V,U) abline(lm3) whereas it should be Either: lm3 - lm(V~U) plot(U,V) abline(lm3) Or: lm3 - lm(U~V) plot(V,U) abline(lm3) Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 18-Dec-2012 Time: 21:00:25 This message was sent by XFMail __ 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] Fwd: I need help with an R function! Thx!
Hi again! I am doing a course about the R software and I have a couple of doubts. In one of the tasks we were asigned, we have to perform a function that simulates a bus' trip with 25 stops. In each of those stops, between 0 and 6 people can go on board. And when the total of passengers reaches 44, no more people can go on board. stops - 25 passengers - 0 *register - numeric(25) *bus - function(register,stops,passengers) { register[1] - passengers for (i in 1:stops) { *passengers - passengers + sample(0:6,1) *register[i] - passengers *} # If the bus isn't full: if (passengers = 44) { # Adjustment if it reaches 44 passenger, before the 25th stop: register[i:stops] - 44 cat('Full bus!\n') # Warning message... break *} else { # If the loop doesn't stop, a new register must be added: register[i] - passengers *} # Para ir viendo cuánto hay: cat('Stop', i, 'hay', passengers, 'passenger\n') } plot(register, xlab='Stop', ylab='No. of passengers') The parts of the script that start with an asterisc are the sectors that we should write, so is in there where my mistakes are. The problem with my script is that when I get the plot the variable passengers is always zero for all the bus' stops. So it seems that my loop isn't able to update the value for each iteration. I would be very glad, if anyone can detect my error, as I have been many days stuck on this part and my deadline is tomorrow. Thanks a lot in advance to everyone. And thanks to Rainer who has recently suggested me to include more information so you could be able to help me. Wanda PS: Sorry for my English! But Spanish is my first language! -- Br. Wanda Iriarte Teléfono de Contacto: 091 33 41 17 Área Genética Dpto. de Genética y Mejora Animal Facultad de Veterinaria, UdelaR Montevideo, Uruguay [[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] multi dimensional optim problem
Forgot to cc the help list. On 18-12-2012, at 19:40, Lu, James T wrote: I am attempting to use optim to solve a neural network problem. I would like to optimize coefficients that are currently stored in a matrix Y=270 x 1 X= 27- x 14 b1= 10x14 b2= 11x1 V= 10 x 14 set of prior variances. I have the following function: posterior.mode1=function(y,X,b_0,b2,V) { log.like=function(b1) { a_g=compute(b1) z_g=tanh(a_g); z_g=cbind(1,z_g) p=softmax(z_g%*%b2); a=sum(y*log(p)+(1-y)*log(1-p)); return(a); } compute=function(b1) { a_g=NULL; for(i in 1:nrow(b1)){ a_g=cbind(a_g,X%*%b1[i,]) } return(a_g); } log.posterior=function(b1) { -log.like(b1)+1/2*t(as.vector(b1))%*%diag(as.vector(V))%*%as.vector(b1) } a=optim(b_0,log.posterior,method=CG,hessian=TRUE) return(a); } When I run posterior.mode1(y,X,b1,b2,b1) I get the following error Error in 1:nrow(b1) : argument of length 0 optim treats parameter b_0 as a vector and passes as such to the function it is trying to optimize. So in log.like you should convert b1 back to a matrix of the correct dimensions like so b1 - matrix(b1,nrow=10) Then it should work. Note: you haven't provided function softmax. Berend __ 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] Regression line does not show on scatterplot
Sorry, I made a mistake in re-writing your code below. See at [***] On 18-Dec-2012 21:00:28 Ted Harding wrote: On 18-Dec-2012 20:09:36 Beatriz González Domínguez wrote: Hello, I have done a scatterplot and now would like to add its regression line but it does not show. Below, the code I have used. lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) abline(lm3) I have been able to do the complete operation using the software STATISTICA but it would be great to do it with R. If you require more details please get in touch. Thanks a lot! Bea By the look of things you have either the regression or the plot the wrong way round. I suspect it is the regression. So try: [***] The following should be correct (I previously mis-copied [***] your variable names). Either: ##lm3 - lm(data$S_pH_KCl2.5_BCx~data$B_OleicoPF_BCx_per) lm3 - lm(data$B_OleicoPF_BCx_per ~ data$S_pH_KCl2.5_BCx) plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) abline(lm3) Or: lm3 - lm(data$S_pH_KCl2.5_BCx ~ data$B_OleicoPF_BCx_per) ##plot(data$S_pH_KCl2.5_BCx, data$B_OleicoPF_BCx_per) plot(data$B_OleicoPF_BCx_per, data$S_pH_KCl2.5_BCx) abline(lm3) The point is that in lm(V~U) the variable U is taken as corresponding the the x-axis (independent variable), and the variable V to the y-axis (dependent variable). Similarly for plot(U,V). So, for lm3 - lm(V~U), abline(lm3) will plot the fitted V-values (y-axis) against the U-values (x-axis). Your original code was equivalent to: lm3 - lm(V~U) plot(V,U) abline(lm3) whereas it should be Either: lm3 - lm(V~U) plot(U,V) abline(lm3) Or: lm3 - lm(U~V) plot(V,U) abline(lm3) Hoping this helps, Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 18-Dec-2012 Time: 21:15:47 This message was sent by XFMail __ 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] Fwd: I need help with an R function! Thx!
Your English is fine, but your intentions are not. This list has a no homework policy. -- Bert On Tue, Dec 18, 2012 at 1:09 PM, Wanda Iriarte wanda.iria...@gmail.comwrote: Hi again! I am doing a course about the R software and I have a couple of doubts. In one of the tasks we were asigned, we have to perform a function that simulates a bus' trip with 25 stops. In each of those stops, between 0 and 6 people can go on board. And when the total of passengers reaches 44, no more people can go on board. stops - 25 passengers - 0 *register - numeric(25) *bus - function(register,stops,passengers) { register[1] - passengers for (i in 1:stops) { *passengers - passengers + sample(0:6,1) *register[i] - passengers *} # If the bus isn't full: if (passengers = 44) { # Adjustment if it reaches 44 passenger, before the 25th stop: register[i:stops] - 44 cat('Full bus!\n') # Warning message... break *} else { # If the loop doesn't stop, a new register must be added: register[i] - passengers *} # Para ir viendo cuánto hay: cat('Stop', i, 'hay', passengers, 'passenger\n') } plot(register, xlab='Stop', ylab='No. of passengers') The parts of the script that start with an asterisc are the sectors that we should write, so is in there where my mistakes are. The problem with my script is that when I get the plot the variable passengers is always zero for all the bus' stops. So it seems that my loop isn't able to update the value for each iteration. I would be very glad, if anyone can detect my error, as I have been many days stuck on this part and my deadline is tomorrow. Thanks a lot in advance to everyone. And thanks to Rainer who has recently suggested me to include more information so you could be able to help me. Wanda PS: Sorry for my English! But Spanish is my first language! -- Br. Wanda Iriarte Teléfono de Contacto: 091 33 41 17 Ãrea Genética Dpto. de Genética y Mejora Animal Facultad de Veterinaria, UdelaR Montevideo, Uruguay [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[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] Fwd: I need help with an R function! Thx!
Hello, There's a no home work policy but since you've obviously tried, here it goes. The main problem with your function is that you are testing outside the loop. Another problem is that your function doesn't return a value. Both problems are corrected. I also include a function that does the same in a vectorized way. As you can see with the tests below, they produce the same output. stops - 25 passengers - 0 register - numeric(25) bus - function(register,stops,passengers) { register[1] - passengers for (i in 1:stops) { passengers - passengers + sample(0:6, 1) register[i] - passengers # Para ir viendo cuanto hay: cat('Stop', i, 'hay', passengers, 'passenger\n') } # If the bus isn't full: if (passengers = 44) { # Adjustment if it reaches 44 passenger, before the 25th stop: register[register = 44] - 44 cat('Full bus!\n') # Warning message... } register # return value } bus2 - function(register,stops,passengers){ passengers - sample(0:6, stops, replace = TRUE) # All at once register - cumsum(passengers) # running sum of passengers register[register = 44] - 44 # adjust for overflow register } set.seed(3862) # To make reproducible runs r1 - bus(register,stops,passengers) set.seed(3862) r2 - bus2(register,stops,passengers) identical(r1, r2) Note that in the corrected version of your function the if test is no longer needed. Hope this helps, Rui Barradas Em 18-12-2012 20:05, Wanda Iriarte escreveu: Hi! I am doing a course about the R software and I have a couple of doubts. In one of the tasks we were asigned, we have to perform a function that simulates a bus' trip with 25 stops. In each of those stops, between 0 and 6 people can go on board. And when the total of passengers reaches 44, no more people can go on board. stops - 25 passengers - 0 register - numeric(25) bus - function(register,stops,passengers) { register[1] - passengers for (i in 1:stops) { passengers - passengers + sample(0:6,1) register[i] - passengers } # If the bus isn't full: if (passengers = 44) { # Adjustment if it reaches 44 passenger, before the 25th stop: register[i:stops] - 44 cat('Full bus!\n') # Warning message... break } else { # If the loop doesn't stop, a new register must be added: register[i] - passengers } # Para ir viendo cuánto hay: cat('Stop', i, 'hay', passengers, 'passenger\n') } plot(register, xlab='Stop', ylab='No. of passengers') The parts of the script that are marked in sky blue, are the ones that we have to fill up, so on of those should be my mistake. I would be very glad, if anyone can detect my error, as I have been many days stuck on this part and my deadline is tomorrow. Thx a lot in advance to everyone. Wanda BTW: Sorry for my English! My native language is Spanish! :) [[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] Breaking out of multiple loops
On 12-12-18 1:02 PM, McCloskey, Bryan wrote: Hey all, I'm currently working through the problems at Project Euler -- this question came up while working on Problem 9 (http://projecteuler.net/problem=9): A Pythagorean triplet is a set of three natural numbers, a b c, for which, a^2 + b^2 = c^2. For example, 3^2 + 4^2 = 9 + 16 = 25 = 5^2. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. Not too hard: n=1000 for(i in 1:floor(n/3)) for(j in (i+1):floor(n/2-i/2)) if(i^2+j^2==(n-i-j)^2) {print(i*j*(n-i-j)); stop()} I could just let the for loops finish looping after it finds the answer, and it would still run in under a second, but the goal of Project Euler is sort of to see how efficiently (and quickly) you can solve these problems, so in that spirit I would like to break out of the for loops early once the answer is found -- hence the call to stop(). However, this seems improper, as it throws up an error. Is there a way to exit out of both for loops with a call to break or similar that would not throw errors (or is it fine the way I've coded it)? (I realize I could put an if(i^2+j^2==(n-i-j)^2) break statement in the outer loop, but again that's inefficient, as it's checking that conditional hundreds of times.) So is there a way to cleanly break out of multiple loops? Put them in a function, and return from the function. Duncan Murdoch __ 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] Set a zero at minimum row by group
This is a bit simpler: df$x_new - ave(df$T, df$ID, FUN=function(x)x!=min(x)) df ID T x x_new 1 1 1 0 0 2 1 2 1 1 3 1 3 1 1 4 2 1 0 0 5 2 4 1 1 6 3 3 0 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 Are you sure there are no ties for the minimum value? -- David L Carlson Associate Professor of Anthropology Texas AM 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 William Dunlap Sent: Tuesday, December 18, 2012 10:45 AM To: Carlos Nasher; r-help@r-project.org Subject: Re: [R] Set a zero at minimum row by group You should show what you tried with aggregate and tapply. You could use ave(): wm - as.logical(ave(df$T, df$ID, FUN=function(x)x==min(x))) df$x_new - df$x df$x_new[wm] - 0 df ID T x x_new 1 1 1 1 0 2 1 2 1 1 3 1 3 1 1 4 2 1 1 0 5 2 4 1 1 6 3 3 1 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 (The as.logical is there because ave() coerces the logical output of FUN to the type of df$T, numeric, and we need to convert it back to logical.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Carlos Nasher Sent: Tuesday, December 18, 2012 6:10 AM To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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-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] Clustering newbie question
Hello, Please advice on encoding data for the following clustering problem. I have a dataset with car usage info. Dataset has the following fields: 1. Car model (Toyoya Celica, BMW, Nissan X-Trail, Mazda Cosmo, etc.) 2. Year built 3. Country where the car runs 4. Distance run by car before major repairs Important: The above dataset is sparse. In most cases Distance is not known for all countries for a given car. Problem: For a given car predict the Distance it will run before major repairs in a country for which Distance is unknown. My approach: I want to represent each record in the dataset as a sparse vector with the following components: 1. Binary (1/0) car model components. Number of these components equals the number of all possible models in the dataset. 2. Binary (1/0) country where the car runs. Number of these components equals the number of all possible countries in the dataset. 3. Distance. A single integer component, equals the distance run by car. Next I want to cluster (k-means) these vectors and analyze resulting groups. Questions: 1) In my vectors I mix components of different nature - binary (model, country) and continuous (distance). How to calculate component-wise distance between vectors? Cosine similarity? 2) Other ways to encode components with finite set of values (model, country) to work well with continuous components (such as distance)? Thanks! Anton [[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] Set a zero at minimum row by group
I used the more complicated version because I didn't know if df$x could contain values other than 0 and 1. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: David L Carlson [mailto:dcarl...@tamu.edu] Sent: Tuesday, December 18, 2012 2:30 PM To: William Dunlap; 'Carlos Nasher'; r-help@r-project.org Subject: RE: [R] Set a zero at minimum row by group This is a bit simpler: df$x_new - ave(df$T, df$ID, FUN=function(x)x!=min(x)) df ID T x x_new 1 1 1 0 0 2 1 2 1 1 3 1 3 1 1 4 2 1 0 0 5 2 4 1 1 6 3 3 0 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 Are you sure there are no ties for the minimum value? -- David L Carlson Associate Professor of Anthropology Texas AM 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 William Dunlap Sent: Tuesday, December 18, 2012 10:45 AM To: Carlos Nasher; r-help@r-project.org Subject: Re: [R] Set a zero at minimum row by group You should show what you tried with aggregate and tapply. You could use ave(): wm - as.logical(ave(df$T, df$ID, FUN=function(x)x==min(x))) df$x_new - df$x df$x_new[wm] - 0 df ID T x x_new 1 1 1 1 0 2 1 2 1 1 3 1 3 1 1 4 2 1 1 0 5 2 4 1 1 6 3 3 1 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 (The as.logical is there because ave() coerces the logical output of FUN to the type of df$T, numeric, and we need to convert it back to logical.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Carlos Nasher Sent: Tuesday, December 18, 2012 6:10 AM To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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-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] Set a zero at minimum row by group
Just noticed that I used a modified copy of df. It should be df ID T x x_new 1 1 1 1 0 2 1 2 1 1 3 1 3 1 1 4 2 1 1 0 5 2 4 1 1 6 3 3 1 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 --- David -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of David L Carlson Sent: Tuesday, December 18, 2012 4:30 PM To: 'William Dunlap'; 'Carlos Nasher'; r-help@r-project.org Subject: Re: [R] Set a zero at minimum row by group This is a bit simpler: df$x_new - ave(df$T, df$ID, FUN=function(x)x!=min(x)) df ID T x x_new 1 1 1 0 0 2 1 2 1 1 3 1 3 1 1 4 2 1 0 0 5 2 4 1 1 6 3 3 0 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 Are you sure there are no ties for the minimum value? -- David L Carlson Associate Professor of Anthropology Texas AM 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 William Dunlap Sent: Tuesday, December 18, 2012 10:45 AM To: Carlos Nasher; r-help@r-project.org Subject: Re: [R] Set a zero at minimum row by group You should show what you tried with aggregate and tapply. You could use ave(): wm - as.logical(ave(df$T, df$ID, FUN=function(x)x==min(x))) df$x_new - df$x df$x_new[wm] - 0 df ID T x x_new 1 1 1 1 0 2 1 2 1 1 3 1 3 1 1 4 2 1 1 0 5 2 4 1 1 6 3 3 1 0 7 3 5 1 1 8 3 6 1 1 9 3 8 1 1 (The as.logical is there because ave() coerces the logical output of FUN to the type of df$T, numeric, and we need to convert it back to logical.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Carlos Nasher Sent: Tuesday, December 18, 2012 6:10 AM To: r-help@r-project.org Subject: [R] Set a zero at minimum row by group Dear R Helpers, I'm struggling with a data preparation problem. I feel that it is a quite easy task but I don't get it done. I hope you can help me with that. I have a data frame looking like this: ID - c(1,1,1,2,2,3,3,3,3) T - c(1,2,3,1,4,3,5,6,8) x - rep(1,9) df - data.frame(ID,T,x) df ID T x 1 1 1 1 2 1 1 3 1 2 1 1 2 4 1 3 3 1 3 5 1 3 6 1 3 8 1 I want to manipulate the x column in a way that for each customer (ID) at the minimum of T the x value is set to zero. The result should look like this: ID T x x_new 1 1 1 0 1 2 1 1 1 3 1 1 2 1 1 0 2 4 1 1 3 3 1 0 3 5 1 1 3 6 1 1 3 8 1 1 I already tried the aggregate() and apply() function, but I don't get the result I'm looking for. I would glad if you could help me out. Best regards, Carlos [[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-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] Using PCNM() in Vegan and calculating Moran's I
Hello- I am using the vegan package PCMN() because I need to use option of row weights (I am using CCA following the selection of the significant/positive PCNM variables). In the library PCNM (PCNM function), the Moran's I is calculated for you as part of the function. I see that I need to calculate Moran's I separately in order to retain the eigenfunctions with positive spatial correlation but could use help in doing so...I have looked up Moran's I in a couple different packages but am not sure what to use... Thanks! [[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 with building taxonomies through package ade4
Hello, Im trying to use the package ade4 to build a taxonomy, though my data isnt biological. Heres the data (a small subset of the real data): dat = matrix(c(070201,0201,01,100201,0201,01,070201,0201, 01,110201,0201,01,020501,0501,01,040102,0102,02,040102 ,0102,02,040102,0102,02,040102,0102,02,040102,0102,02 ),10,3,byrow=T) dat = cbind(as.character(1:10), dat) colnames(dat) = c(phrase,species,genus,family) The line, tax = as.taxo(data.frame(dat)) works fine, though doesnt do much. The line, tax.phy - taxo2phylog(tax,add.tools=TRUE) Generates the following error: Error in eigen(w, sym = TRUE) : infinite or missing values in 'x' Can anyone explain this, or tell me how to format the data in order to produce the taxonomy? I'm not sure where eigen()is being called, how I can get it to ignore this error, and I doubt that I need the results for my purposes anyway. Thanks and best regards, -Mitchell Ohriner Winchester, VA USA [[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] Using PCNM() in Vegan and calculating Moran's I
Hello, I generally use 'moran.test' and 'moran.mc' from the 'spdep' package. Regards, Pascal Le 19/12/2012 09:02, Chase, Jennifer a écrit : Hello- I am using the vegan package PCMN() because I need to use option of row weights (I am using CCA following the selection of the significant/positive PCNM variables). In the library PCNM (PCNM function), the Moran's I is calculated for you as part of the function. I see that I need to calculate Moran's I separately in order to retain the eigenfunctions with positive spatial correlation but could use help in doing so...I have looked up Moran's I in a couple different packages but am not sure what to use... Thanks! [[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] SNPRelate problems
Hi, I'm trying convert plink files to gds (SNPRelate). I have the files: baep.fam, baep.bed and baep.bim and the program to convert data is: setwd('C:/Silvano/Incor/Baependi/Dados Baependi/') library(gdsfmt)# versão 0.9.10 library(SNPRelate) # versão 0.9.8 # Arquivos PLINK BED bed.fn - system.file(C:/Silvano/Incor/Baependi/Dados Baependi/, baep.bed, package=SNPRelate) bim.fn - system.file(C:/Silvano/Incor/Baependi/Dados Baependi/, baep.bim, package=SNPRelate) fam.fn - system.file(C:/Silvano/Incor/Baependi/Dados Baependi/, baep.fam, package=SNPRelate) # Convertendo snpgdsBED2GDS(bed.fn, fam.fn, bim.fn, out.gdsfn=C:/Silvano/Incor/Baependi/Dados Baependi/baep.gds, verbose=TRUE) but isn't work. The error is: Start snpgdsBED2GDS ... Erro em snpgdsBED2GDS(bed.fn, fam.fn, bim.fn, out.gdsfn = C:/Silvano/Incor/Baependi/Dados Baependi/baep.gds, : Cannot open the file . What can I do? What is wrong? Thanks, - Silvano Cesar da Costa Universidade Estadual de Londrina Centro de Ciências Exatas Departamento de Estatística Fone: (43) 3371-4346 __ 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] random sampling matrix
Hello I have a one question about random sampling matrix I want to regeneration value of matrix For example, Matrix A : 1 2 3 11 12 13 21 22 23 . sample= data.frame(a[sample(1:dim(a)[1]),sample(1:dim(a)[2])]) Then, Matrix sample : 21 23 22 11 13 12 1 3 2 But, I want to regeneration. Ex) Matrix sample 1 23 2 22 11 3 12 21 13 Pleases kindly help with R code¡¦ Thank you. [[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] How to convert xts data into list
Hello, How can I convert Close colume of the below xts time series data into a list of Close values ? I'd like to plot Close values as a list. gt; head(zc) Close (10/15/12 09:00:00) 252.40 (10/15/12 09:01:00) 253.10 (10/15/12 09:02:00) 253.15 (10/15/12 09:03:00) 253.30 (10/15/12 09:04:00) 253.25 (10/15/12 09:05:00) 253.45 I tried the below command to plot it. But it failed. gt; plot(1:length(zc$Close),as.list(zc$Close)) Thanks in advance, SK Park [[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] random sampling matrix
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ??? Sent: Tuesday, December 18, 2012 9:08 PM To: r-help@r-project.org Subject: [R] random sampling matrix Hello I have a one question about random sampling matrix I want to regeneration value of matrix For example, Matrix A : 1 2 3 11 12 13 21 22 23 . sample= data.frame(a[sample(1:dim(a)[1]),sample(1:dim(a)[2])]) Then, Matrix sample : 21 23 22 11 13 12 1 3 2 But, I want to regeneration. Ex) Matrix sample 1 23 2 22 11 3 12 21 13 Pleases kindly help with R code! Thank you. Does this do what you want? m - matrix(c(1,21,31,2,22,23,3,23,33), nrow=3) m [,1] [,2] [,3] [1,]123 [2,] 21 22 23 [3,] 31 23 33 matrix(sample(m),nrow=3) [,1] [,2] [,3] [1,] 33 231 [2,]23 22 [3,] 31 23 21 matrix(sample(m),nrow=3) [,1] [,2] [,3] [1,] 21 231 [2,] 31 33 23 [3,]23 22 matrix(sample(m),nrow=3) [,1] [,2] [,3] [1,] 312 21 [2,] 331 22 [3,] 23 233 Hope this is helpful, Dan Daniel Nordlund Bothell, WA 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.