[R] Replace sub string
Given: filename-paste(tempdir(),\\,myfile.txt,sep=); sub(,/,filename); [1] C:/DOCUME~1\\AJAYAS~1\\LOCALS~1\\Temp\\Rtmp2f270T\\myfile.txt Note: Only the first occurence of \\ is replaced. What is the syntax for replacing every occurence? 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] Replace sub string
Thanks. 1. For consistency: I am using / everywhere else in my script. 2. For ease of use: I am passing the string to a client application (using rcom) where it is easeir to handle / than \\. See ?gsub But why would you do that? Both / and \\ are valid in a path, aren't they? Ivan [[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] Removing session variables
If I create a data.frame using session variables as follows: classResults-data.frame(subjEnglish,gradeEnglish,subjFrench,gradeFrench,row.names=studentName) How can I remove the variables? I tried rm(names(classResults)) Error in rm(names(classResults)) : ... must contain names or character strings Also, how can I include the row.names variable. I tried names(classResults) [1] subjEnglish gradeEnglish subjFrench gradeFrench but this does not include that name. 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] paste (CTRL + v) not working rgui
I've definitely encountered problems when running programs without administrator righs. Perhaps that was down to virus/spyware protection software. At this linkhttp://forums.techarena.in/windows-software/1258938.htm there is the following suggestion 1.Click on Start 2.Type Run in Search and hit Enter 3.Type services.msc and hit enter 4.Find These services: â¦Network DDE DSDM. â¦Network DDE. â¦Clipbook. 5.Right Click on Each 6.And select Restart NOt tried it - as I do not have the prolem - but it sounds plausible.  The alternative to the first 3 steps is Administration Tools + SERVICES [[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] Classification by range
Given studentNumbers-10; subjEnglish-sample(-1:100,studentNumbers,replace=TRUE); when subEnglish =0, 'U' =39, 'F' =49 'D' =59, 'C' =69, 'B' =79,'A' =100 'A+' I can solve this using a series of 'if' 'else' statements. I am looking for a simple expression that will give the letter classification for every element of subEnglish. Is there on? 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] Can a matrix with several rows and columns ...
be sorted by row in ascending/descending order? Given this matrix: 57 91 31 61 16 84 3 99 85 47 21 6 57 91 31 61 16 84 3 99 I want to end with this: 21 6 57 91 31 57 91 31 61 16 61 16 84 3 99 84 3 99 85 47 The 'order' of the sort is: 3 1 4 2 Also, what R expression will give me the 'order'? 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] Can a matrix with several rows and columns ...
Thank you. Yes, I did look at the help but could not get my expressions to work. You used a data.frame with thematrix values I gave. Your solution also works when dealing with a matrix (this my be obvious to seasoned R users, but was no to me). x-matrix(c(57,91,31,61,16,84,3,99,85,47,21,6,57,91,31,61,16,84,3,99), ncol=5, byrow=TRUE) #order by row order(x[,1]) [1] 3 1 4 2 x[order(x[,1]),] [,1] [,2] [,3] [,4] [,5] [1,] 21 6 57 91 31 [2,] 57 91 31 61 16 [3,] 61 16 84 3 99 [4,] 84 3 99 85 47 #order by column order(x[1,]) [1] 5 3 1 4 2 x[,order(x[1,])] [,1] [,2] [,3] [,4] [,5] [1,] 16 31 57 61 91 [2,] 47 99 84 85 3 [3,] 31 57 21 91 6 [4,] 99 84 61 3 16 [[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] Why aren't row names in a data frame unique?
Jim, have a look here: http://www.r-bloggers.com/select-operations-on-r-data-frames/. Specifically at the Duplicate Row Names section towards the end of the page. From: Jim Lemon j...@bitwrit.com.au Cc: R General Forum r-help@r-project.org Sent: Tuesday, 6 March 2012, 9:42 Subject: Re: [R] Why aren't row names in a data frame unique? On 03/06/2012 06:42 PM, Ajay Askoolum wrote: I expected the row names to be unique but a data frame appears to be able to hold duplicate row names. This makes me thing that there must be circumstances when it is necessary. However, I cannot think of any. Please enlighten me. Hi Ajay, An example of how you managed to do this would be helpful. I tried it: dodo-data.frame(a=1:3,b=4:6) dodo  a b 1 1 4 2 2 5 3 3 6 rownames(dodo)-c(s,t,s) Error in `row.names-.data.frame`(`*tmp*`, value = value) :  duplicate 'row.names' are not allowed In addition: Warning message: non-unique value when setting 'row.names': âsâ Jim [[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] Why aren't row names in a data frame unique?
I expected the row names to be unique but a data frame appears to be able to hold duplicate row names. This makes me thing that there must be circumstances when it is necessary. However, I cannot think of any. Please enlighten me. [[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] Changing the frequency of time series
I know how to do this when creating the time series variable in one expression, e.g. valuesTS1-ts(values,start=2000); # Frequency naturally defaults to 1 How can I specify the frequency of a time series? values=c(12,34,65,12); values-ts(values); frequency(values); [1] 1 start(values) [1] 1 1 frequency(values)-12; Error in frequency(values) - 12 : could not find function frequency- [[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] RServe
One line of the RServe documentation (for Java, which I do not know) is: Rconnection c = new Rconnection(); 1. Is Rserve a COM or ActiveX object? If affirmative, what is the ProgId (or clsid)? 2. If Rserve is not an ActiveX Object, does Java (like C#) require a reference to the EXE or DLL that is Rconnection? If affirmative, what is the full name of that EXE or DLL? I am attempting to see if I can use Rserve from C# and would appreciate any help in getting started. 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] How do I save the current session?
savehistory() gives me the option of saving the executable lines only. I'd like to save everything. [[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] Confused: Inconsistent result?
This is copy paste from my session: xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class dim(xyz)-c(length(xyz)/2,2) allobj-function(){ + xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } xyz [,1] [,2] [1,] a character [2,] aa character [3,] abc character [4,] AirPassengers character [5,] allobj character [6,] allObjects character [7,] allObjects2 character [8,] arrayFromAPL character [9,] classes character [10,] myCharVector character [11,] myDateVector character [12,] myNumericVector character [13,] newArrayFromAPL character [14,] obj character [15,] objClass character [16,] x character [17,] xyz character [18,] y character allobj() [,1] [,2] As far as I can see, the function allobj has the same expressions as those executed from the command line. Why are the results different? [[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] Dataframe subset - why doesn't this work?
data(mtcars) mtcars[rownames(mtcars)!=Valiant,] # fails mtcars[list(rownames(mtcars))!=Valiant,] # runs but I am not getting the expected result With the latter statement, I expected all rows except the one where the name is Valiant. I must have got something simple wrong; what is it? 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] R's list data structure
Given dayOfWeekName-c(Mon,Tue,Wed,Thu,Fri,Sat,Sun); dayOfWeekOrdinal-c(1,2,3,4,5,6,0); dayOfWeekWorkDay-c(TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,FALSE); weekProfile-list(dow=dayOfWeekName,dowI=dayOfWeekOrdinal,dowW=dayOfWeekWorkDay) 1. How can I conditionally get dow, dowI, and dowW from weekProfile? If another 'arrangement' of this list object will make this task easier, please advise. 2. What is the point of the list object? I know that when mixed data types need to be held together, then the only option is to use the list data structure. If I were to hold recurring (Name, Salary, DateOfBirth) (i.e. character, integer and date values) in a list object, what would be the 'optimal' arrangement? Would that be as the components of weekProfile above? Or will this be better. Either: personalDetail- list(rbind(c(Name,Salary,DateOfBirth),c(Name,Salary,DateOfBirth))); Thanks for sharing your insight. [[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] Dataframe subset - why doesn't this work?
Thank you Jorge Michael. I was being stupid - its the only explanation! The line I had been executing was mtcars[rownames==Valiant] # missing rownames argument but the line I quoted in my post was mtcars[rownames(mtcars) != Valiant,] # How could I write the correct line in the mailing list and not where it matters i.e in R? 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.
Re: [R] R's list data structure
Hi Sarah, Thanks you for the clarifications; I had worked round the problem by switching to a data.frame. However, I am still unclear about 'list': as it exists, it must have a purpose. When is the use of the list data structure appropriate? [[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] User Interface Equivalent Code
When I plot, the plot's user interface offers me a choice: File | Copy to the Clipboard | as a Bitmap. What is the equivalent code for achieving this but without the plot interface becoming visible? 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] Data Structure to Code
Given: data(AirPassengers) I get a ts data structure AirPassengers in the workspace. How can I generate the code that can create that structure? That is, given an example of a data structure, is there a way to generate the code that can greate that structure? Alternatively, is there a reference that provides a list of dta structures together with a full list of theor respective attributes? [[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] Data Structure to Code
Thank you. I need some clarification. dput(AirPassengers) gives: structure(c(112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118, 115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114, 140, 145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166, 171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194, 196, 196, 236, 235, 229, 243, 264, 272, 237, 211, 180, 201, 204, 188, 235, 227, 234, 264, 302, 293, 259, 229, 203, 229, 242, 233, 267, 269, 270, 315, 364, 347, 312, 274, 237, 278, 284, 277, 317, 313, 318, 374, 413, 405, 355, 306, 271, 306, 315, 301, 356, 348, 355, 422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348, 363, 435, 491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472, 548, 559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606, 508, 461, 390, 432), .Tsp = c(1949, 1960.917, 12), class = ts) and AirPassengers looks as follows: AirPassengers Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1949 112 118 132 129 121 135 148 148 136 119 104 118 1950 115 126 141 135 125 149 170 170 158 133 114 140 1951 145 150 178 163 172 178 199 199 184 162 146 166 1952 171 180 193 181 183 218 230 242 209 191 172 194 1953 196 196 236 235 229 243 264 272 237 211 180 201 1954 204 188 235 227 234 264 302 293 259 229 203 229 1955 242 233 267 269 270 315 364 347 312 274 237 278 1956 284 277 317 313 318 374 413 405 355 306 271 306 1957 315 301 356 348 355 422 465 467 404 347 305 336 1958 340 318 362 348 363 435 491 505 404 359 310 337 1959 360 342 406 396 420 472 548 559 463 407 362 405 1960 417 391 419 461 472 535 622 606 508 461 390 432 Where are the column headers in the result of dput(AirPassengers)? I guess it must be something to do with the '12' in the final argument of .Tsp. So, If I just wanted 'Jan' ... 'Jun' and specified the following: structure(c(112, 118, 132, 129, 121, 135, 148, 148, 136, 119, 104, 118, 115, 126, 141, 135, 125, 149, 170, 170, 158, 133, 114, 140, 145, 150, 178, 163, 172, 178, 199, 199, 184, 162, 146, 166, 171, 180, 193, 181, 183, 218, 230, 242, 209, 191, 172, 194, 196, 196, 236, 235, 229, 243, 264, 272, 237, 211, 180, 201, 204, 188, 235, 227, 234, 264, 302, 293, 259, 229, 203, 229, 242, 233, 267, 269, 270, 315, 364, 347, 312, 274, 237, 278, 284, 277, 317, 313, 318, 374, 413, 405, 355, 306, 271, 306, 315, 301, 356, 348, 355, 422, 465, 467, 404, 347, 305, 336, 340, 318, 362, 348, 363, 435, 491, 505, 404, 359, 310, 337, 360, 342, 406, 396, 420, 472, 548, 559, 463, 407, 362, 405, 417, 391, 419, 461, 472, 535, 622, 606, 508, 461, 390, 432), .Tsp = c(1949, 1972, 6), class = ts) Why does this generate invalid time series parameters specified? [[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 I assign the result of a plot to a variable?
I can write a plot to a files of a given format using this: x-sample(c(1:100),10) bmp(c:/mygraph.bmp) plot(x) dev.off() and then show the image file in another application. This application can also display the image from the stream of numbers that define the image. How I can get the plot as a stream of numbers? [[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 write the entire session to file?
savehistory writes all the executed lines from the session. How can I write everything (executed lines and output) from the active session to a file? Using Edit | Select All then Edit Copy, I can copy everything to the clipboard and write the whole thing to a file manually. If I just used the clipboard, I can paste the whole content into another edittor (for documentation). Is there a way to copy the content of the session with the syntax colouring? 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] What does [[1]] mean?
I know that [] is used for indexing. I know that [[]] is used for reference to a property of a COM object. I cannot find any explanation of what [[1]] does or, more pertinently, where it should be used. 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] List to Array: How to establish the dimension of the array
Given a variable aa in the workspace, some of its attributes are: typeof(aa) [1] list mode(aa) [1] list length(aa) [1] 2 How do I retrieve the maximum indices, in this case 2,3,4? The variable itself is: aa [[1]] [[1]][[1]] [[1]][[1]][[1]] [1] 37531.52 [[1]][[1]][[2]] [1] 62787.32 [[1]][[1]][[3]] [1] 5503.184 [[1]][[1]][[4]] [1] 33832.8 [[1]][[2]] [[1]][[2]][[1]] [1] 20469.6 [[1]][[2]][[2]] [1] 27057.27 [[1]][[2]][[3]] [1] 51160.25 [[1]][[2]][[4]] [1] 45165.24 [[1]][[3]] [[1]][[3]][[1]] [1] 957.932 [[1]][[3]][[2]] [1] 21902.94 [[1]][[3]][[3]] [1] 37531.52 [[1]][[3]][[4]] [1] 62787.32 [[2]] [[2]][[1]] [[2]][[1]][[1]] [1] 5503.184 [[2]][[1]][[2]] [1] 33832.8 [[2]][[1]][[3]] [1] 20469.6 [[2]][[1]][[4]] [1] 27057.27 [[2]][[2]] [[2]][[2]][[1]] [1] 51160.25 [[2]][[2]][[2]] [1] 45165.24 [[2]][[2]][[3]] [1] 957.932 [[2]][[2]][[4]] [1] 21902.94 [[2]][[3]] [[2]][[3]][[1]] [1] 37531.52 [[2]][[3]][[2]] [1] 62787.32 [[2]][[3]][[3]] [1] 5503.184 [[2]][[3]][[4]] [1] 33832.8 [[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] List to Array: How to establish the dimension of the array
Thanks you, I can get the length of aa with length(unlist(aa)). If aa has 4 dimensions, I imagine I'd need to do max(sapply(aa,sapply,sapply,length) How can I do this in a generic way? That is in a loop. I am clear about the exit condition for the loop. d-1 start loop if d = length(unlist(aa)) then exit loop else d-d * expr How do I construct expr such that it does d- d * length(aa) # first pass d- d * max(sapply(aa, length)) # second pass d- d * max(sapply(aa, sapply, length)) # third pass # ? # # fourth path etc (Apologies for the pseudo code describing the loop; I am not near a machine with R) One way I can thing of is to create a loop counter variable, say lc-1 and to increment it within the loop and then use a switch statement to execute the appropriate expression. This sems like a kludge to me. Is there a neater way? [[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] R interactive = FALSE
I haven't been able to find an example of using R with interactive = FALSE. How do I start R such that 1. it loads a workspace 2. then starts execution with a function (in that workspace) that I choose 3. exits on completion 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] How to identify data structure?
data(AirPassengers) brings AirPassengers into the workspace. How can I idenfity what the structure of AirPassengers is? Is it a data.frame, a table etc. etc. [[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 identify data structure?
Thank you. class(AirPassengers) is what I was looking for i.e. a generic way of identification. [[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] Enumerate the class of objects
ls() gives me the vector of objects in the workspace class(objName) gives me the class of objName class(ls()) just returns character as many times as there are objects. How do I get a vector of all objects in the workspace? [[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] Executable Expressions II
Thank you very much for this information. From: R. Michael Weylandt michael.weyla...@gmail.com Cc: Richard M. Heiberger r...@temple.edu; R General Forum r-help@r-project.org Sent: Thursday, 19 January 2012, 19:17 Subject: Re: [R] Executable Expressions II Glad you got it worked out -- I don't know C# but if it's portable-ish to C++ you may also want to look at Dirk's RInside project: http://dirk.eddelbuettel.com/code/rinside.html and here in web-deployment http://dirk.eddelbuettel.com/blog/2011/11/30/#rinside_and_wt Michael I am not using RExcel at all. I have now come up with a better solution that using eval. I can construct the data structure (like c(1,2,3,4,5)) as an object in C# and pass it as the argument to the method inside the web service that will call R. Works fine. [[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.
[R] What is a 'closure'?
The R Language Definition at http://cran.r-project.org/doc/manuals/R-lang.html states in the following section 4.3.2 Argument matching This subsection applies to closures but not to primitive functions. What are 'closures'? [[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] What is a 'closure'?
Michael, thank you, especially for the link. I think I understand. The vocabulary is so different! I know 'closure' as 'user-defined function'. [[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] What is a 'closure'?
Thanks for clarifying. Is my (new) understanding stated below correct? - A closure is any function (user- or system- defined) where is.primitive(functionName) is FALSE. - is.primitive(functionName) is FALSE when functionName is a system-defined function that is coded in R itself. [[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] R Table
Given a table with colnames and rownames, print(mytable) displays the table nicely formatted. How can I capture all of what is displayed as a character matrix? 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] R Table
Thank you. I used capture.output(); this is fine. From: R. Michael Weylandt michael.weyla...@gmail.com Cc: R General Forum r-help@r-project.org Sent: Wednesday, 18 January 2012, 19:44 Subject: Re: [R] R Table Capture in what file format / device? If you want a plain text log, sink() or capture.output() probably will do it. MASS::write.table() might also help. I believe library(Hmisc) has some functions for converting to LaTeX tables as well, but I haven't used those myself. Michael Given a table with colnames and rownames, print(mytable) displays the table nicely formatted. How can I capture all of what is displayed as a character matrix? 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. [[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] Executable expressions
Given a-c(1,2,3,4,5) How can I evaluate the variable a to return a (numeric) vector comprising of 1,2,3,4,5? 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] Executable Expressions II
Thank you Michael, Sarah and Robin for the answers to my original question. Michael you asked:But this is rarely a good ideaperhaps you could say a little more about your overall goal and we could direct you to a more R-ish solution? I realise eval (known as execute in one of my other languages) is not a good idea. The background to my question is as follows: Using rcom rscproxy, I can deploy R as a COM server inside a C# or VB SOAP Web Service. Any methods that I write in the web service, will need input (or arguments) of unknown length or type etc. Say, (trivial example) I wanted R to give me the mean, median of c(1,2,3,4,5), I can pass c(1,2,3,4,5) as the argument, have R eval it return the results. Do I make sense? [[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] Executable Expressions II
I am not using RExcel at all. I have now come up with a better solution that using eval. I can construct the data structure (like c(1,2,3,4,5)) as an object in C# and pass it as the argument to the method inside the web service that will call R. Works fine. [[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] list: index of the element, that is TRUE
Given Mylist - list(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE) Try which(as.logical(MyList)) to return the indices where Mylist is TRUE. [[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] R for Windows: Is there a function/package that enables Win32 API Calls?
I am looking for a means to call Win32 API calls from R for Windows. Is that possible? 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] R for Windows: Is there a function/package that enables Win32 API Calls?
As far as I can see, R's system, shell etc. functions either call/launch functionality in the core operating system (COMMAND.COM) or free standing exes. Win32 APIs are buried inside operating system synamic link libraries (DLLs) and can be called by other languages. An example is: Function PathFileExists Lib shlwapi.dll Alias PathFileExistsA (ByVal pszPath As String) As Long Here, the API is PathFileExists, which is found in SHWAPI.DLL; it requires a characer argument that is either the name of a file or directory and returns TRUE if it exists or FALSE if it doesn't. A number of these APIs are available in R builtin functions but there are others that aren't. I asked the question because if there is a way in R to call these APIs. a great deal of time can be saved. [[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] Determining if an object name does not exist
Is there a way to tell whether an object name 1. is valid 2. is not going to cause a collision with an existing object by the same name? 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] Extracting Data from SQL Server
try: SELECT a.UNIQUE_ID, a.diag01 from LoadPUS a left join CVD_ICD10 b on a.diag01 = b.[ICD-10 Codes] or a.diag02 = b.[ICD-10 Codes] or a.diag03 = b.[ICD-10 Codes] I am not sure why your table name CVD_ICD10 has a suffix $. From: Jeff Newmiller jdnew...@dcn.davis.ca.us To: dthomas dyfed.tho...@midlandshn.health.nz; r-help@r-project.org Sent: Tuesday, 10 January 2012, 8:00 Subject: Re: [R] Extracting Data from SQL Server This is OT here. However, you might want to investigate the UNIQUE keyword in the SQL Server documentation for SELECT. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. dthomas dyfed.tho...@midlandshn.health.nz wrote: Hi, I am new to R (and rusty on SQL!) and I'm trying to extract records from a SQL server database. I have a table of patient records (LoadPUS) which have three code columns which i want to evaluate against a list of particular codes (CVD_ICD$ table). Given the size of the patient table I want to restrict the data I pull into R to the data I only want to analyse so I am using SQL to do this. The code i have is as follows: library(RODBC) channel-odbcConnect(NatCollections) query-SELECT UNIQUE_ID, diag01 from LoadPUS WHERE (diag01 IN (SELECT [ICD-10 Codes] From CVD_ICD10$)) OR (diag02 IN (SELECT [ICD-10 Codes] From CVD_ICD10$)) OR (diag03 IN (SELECT [ICD-10 Codes] From CVD_ICD10$)) This returns duplicate values, I don't want to hardcode the values because it is quite a long list. Running the IN function just for diag01 returns the correct number of records, however when combining with another IN function it doesn't return the correct number of records. Can you see where my SQL is incorrect or is there another way of doing this? Much appreciated, D -- View this message in context: http://r.789695.n4.nabble.com/Extracting-Data-from-SQL-Server-tp4281000p4281000.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. [[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] RODBC vs gdata
If you use Excel and are prepared to use the RCOM package, another option for reading Excel workbooks becomes available: ado-comCreateObject(ADODB.RecordSet) sql-SELECT * FROM [Sheet1$] con-Provider=Microsoft.ACE.OLEDB.12.0;Data Source=XLSDataSource.xlsx;Extended Properties='Excel 12.0 Xml;IMEX=1;HDR=YES' comInvoke(ado,Open,sql,con) comInvoke(ado,MoveFirst) abc-t(comInvoke(ado,GetRows)) To try this script: 1. Create a workbook named XLSDataSource.xlsx; save it where getwd() indicates. 2. In sheet1, type column names in Row 1, starting in Cell A1 3. Type some typical values under each column where yo have added names Here's what my session shows: source(C:\\AJAY\\RSTATS\\SCRIPTS\\ADO.R) abc [,1] [,2] [1,] 122 Jan [2,] 133 Feb attr(,class) [1] rcomdata PS: If you want to use ADO, it is worthwhile getting to knpw all the methods applicable to the ResordSet object; it is very flexible. From: Enrico Schumann enricoschum...@yahoo.de To: Christof Kluß ckl...@email.uni-kiel.de Cc: r-h...@stat.math.ethz.ch Sent: Monday, 9 January 2012, 20:28 Subject: Re: [R] RODBC vs gdata You could prepare the data in Excel as text, and then coerce them to numeric in R (and approriately code your FG 1 strings). Depending on how large your file is, you could create a new file, format the cells as text, and then copy the data into this new file. Or change cell entries to text by prepending a single quote. For instance, '100 (without the outer quotes) would be displayed as 100 in Excel, but not be evaluated as a number. (But I have used the latter approach only with Excel 2003.) But as someone else has suggested: if you do not have to use Excel, the best thing is not to use it... Regards, Enrico Am 09.01.2012 19:46, schrieb Christof Kluß: Hi Enrico, thank you very much, so it is a known problem with the Microsoft Excel ODBC drivers :( 7 Excel Drivers ... There are at least two known problems with reading columns that do not have a format set before data entry, and so start with format `General'. First, the driver uses the first few rows to determined the column type, and is over-fond of declaring `Numeric' even when there are non-numeric entries. ... Second, if a column is declared as `Text', numeric entries will be read as SQL nulls and hence R NAs. Unfortunately, in neither case does reformatting the column help. So I think I have to use gdata to be sure to read all datas. regards Christof Am 09-01-2012 19:29, schrieb Enrico Schumann: Hi Christof, have a look at the manual of RODBC, and in particular the section on Excel drivers. RShowDoc(RODBC, package=RODBC) Regards, Enrico Am 09.01.2012 19:02, schrieb Christof Kluß: Hi one col in my Excel file contains many numbers. But on line 3000 and some other lines are strings like FG 1. RODBS seems to omit this lines. gdata works, but is much slower. Is this a bug of RODBC or do I apply it wrong? Example with the same file.xlsx library(RODBC); excel- odbcConnectExcel2007(file.xlsx) tab- sqlQuery(excel, 'select * from Table 1$'); str(tab) col1: num 1 2 3 4 5 6 7 8 9 10 ... library(gdata); tab- read.xls(file.xlsx, sheet=1); str(tab) col1: Factor w/ 51 levels 1,10,11,..: 1 12 23 34 41 42 43... greeting Christof __ 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. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ __ 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.