Re: [R] Setting Windows environment variables via a batch file
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Dennis Fisher Sent: Tuesday, August 23, 2011 11:40 AM To: r-h...@stat.math.ethz.ch Subject: [R] Setting Windows environment variables via a batch file R 2.13 Vista Colleagues, I have encountered a problem with Windows environment variables that I don't understand. My R code is designed to execute another program that uses Intel Fortran. Intel Fortran apparently has some complicated issues regarding environment variables. As a result, Intel provides a batch file (FortranVars.bat) that sets all the environment variables. If I am working at a Command Prompt (i.e., at the command line, not in R), the following happens: 1. When I open the Command Prompt, I type set %path% and I get some output 2. I then execute the batch file - the batch batch file returns a message Intel (R) Visual Fortran ... indicating that it was executed (and there is no error or warning from the OS). 3. If I type set %path% again, the output reflects the environment variables added by the batch file. So far, so good. Now I try the same from within R. 1. I type shell(set) and I examine the output for path (for unclear reasons, executing shell(set %path%) resulted in a warning: running command ... had status 1 2. i then execute the batch file -- same message as before 3. I type shell(set) -- the output is unchanged. 4. I also tried executing step 2 preceded by @ call. no success. I am not sure where the problem lies (incidentally, the behavior may be different in Windows 7 so I would appreciate answers relevant to Vista). Does anybody have any insights? Dennis, The problem is that when the shell command finishes and returns to R, all changes made go away. The changes only persist while the shell is open. The same thing happens when you open a command prompt outside of R, change the path, then close the command prompt. The next time you open a command prompt the changes you made to the path are no longer there. You will need to provide more information on how you are calling your Fortran program, before anyone can provide much assistance. As for the getting just the path, you can use shell('set path') hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 require() vs. library()
A recent post prompts me to ask this question. Is there any reason to prefer using library() over require()? I tend to use require() instead of library() to load packages, but I wonder if there are situations where it would be better to use library(). Enquiring minds would like to know, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 require() vs. library()
-Original Message- From: istaz...@gmail.com [mailto:istaz...@gmail.com] On Behalf Of Ista Zahn Sent: Wednesday, August 17, 2011 10:12 AM To: Nordlund, Dan (DSHS/RDA) Cc: r-help@r-project.org Subject: Re: [R] Using require() vs. library() Hi Dan, Is there something you would like to know that is not covered by help(library) ? Best, Ista On Wed, Aug 17, 2011 at 12:40 PM, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: A recent post prompts me to ask this question. Is there any reason to prefer using library() over require()? I tend to use require() instead of library() to load packages, but I wonder if there are situations where it would be better to use library(). Well, I guess when I read that require is designed for use inside other functions... I wasn't sure if that meant there might be times when it would be better to use library when not inside other functions. But maybe it was more generally a question about style, prompted by a post responding to the common confusion between the terms 'package' and 'library' amongst those new to R. To me, it always seemed more natural type require(my.package) than library(my.package). I just wanted to make sure I wasn't missing something that might make me regret that choice. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 require() vs. library()
-Original Message- From: Uwe Ligges [mailto:lig...@statistik.tu-dortmund.de] Sent: Wednesday, August 17, 2011 11:14 AM To: Nordlund, Dan (DSHS/RDA) Cc: r-help@r-project.org Subject: Re: [R] Using require() vs. library() Actually require() is a wrapper around library() with more error handling to be used inside other functions. Just type require(), you can read the few lines of code quickly. Uwe Ligges Thanks Uwe, I will do that. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Newbie question - struggling with boxplots
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ista Zahn Sent: Tuesday, August 16, 2011 4:13 PM To: g.st...@hourglazz.com Cc: r-help@r-project.org Subject: Re: [R] Newbie question - struggling with boxplots On Tue, Aug 16, 2011 at 5:24 PM, Geoffrey Stoel g.st...@hourglazz.com wrote: Hopefully I will not be flamed for this on the list, but I am starting out with R and having some trouble with combining plots. I am playing with the famous iris dataset (checking out example dataset in R while reading through Introduction to datamining) What I would like to do is create three graphs (combined boxplots) besides each other for each of the three species (Setosa, Versicolour and Virginica) with each graph showing showing four boxplots Sepal.Length, Sepal.Width, Petal.Length and Petal.Width. I can create the boxplot for the total dataset by doing the following: data(iris); boxplot(iris[1:4]); However I would like to have this repeated for each Species in iris$Species, I know I can do this with: boxplot(subset(iris,Species==setosa, select = (1:4))); boxplot(subset(iris,Species==versicolor, select = (1:4))); boxplot(subset(iris,Species==virginica, select = (1:4))); but I am lazy AND I want all three to be plotted besides each other AND I don't want to manually type the Species myself. is there an easier way to do this probably yes... You could use ggplot, like this: library(ggplot2) iris.m - melt(iris, id = Species) ggplot(iris.m, aes(x = variable, y = value)) + geom_boxplot() + facet_wrap(~Species, nrow = 1) best, Ista If you want to help me out... would be deeply appreciated.. Kind regards, Geoffrey (new to R and datamining) Nice plot. I know that this is pretty much what the OP asked for, but I find the arrangement below a little easier to make sense of. ggplot(iris.m, aes(x = Species, y = value)) + geom_boxplot() + facet_wrap(~variable, nrow = 1) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Convert matrix to numeric
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Ken Sent: Wednesday, August 03, 2011 12:13 PM To: Jeffrey Joh Cc: r-help@r-project.org Subject: Re: [R] Convert matrix to numeric How about Matrix[1:5,]=as.numeric(Matrix[1:5,]) -Ken Hutchison On Aug 3, 2554 BE, at 3:04 PM, Jeffrey Joh johjeff...@hotmail.com wrote: I have a matrix that looks like this: structure(c(0.0376673981759913, 0.111066500741386, 1, 1103, 18, OPEN, DEPR, 0.0404073656092023, 0.115186044704599, 1, 719, 18, OPEN, DEPR, 0.0665342096693433, 0.197570061769498, 1, 1103, 18, OPEN, DEPR, 0.119287147905722, 0.356427096010845, 1, 1103, 18, OPEN, DEPR), .Dim = c(7L, 4L), .Dimnames = list( c(Sn, SlnC, housenum, date, hour, flue, pressurization ), c(10019.BLO, 1002.BLO, 10020.BLO, 10021.BLO))) How do I convert rows 1-5 to numeric? I tried mode() - numeric but that doesn't change anything. Ken, You can't store the numeric values back in the matrix, because rows 6 and 7 contain character values. Everything will just be converted back to character. You need to create a new matrix for the numeric values. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Standard Deviation of a matrix
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of chakri Sent: Tuesday, August 02, 2011 6:31 AM To: r-help@r-project.org Subject: Re: [R] Standard Deviation of a matrix Thank you everyone for your kind input, I forgot to add that I have decimal points in my matrix ! Enclosed input file (reduced to 10 X 10 matrix), scripts and output for your suggesions: Code 1: library(stats) Matrix-read.table(test_input, head=T, sep= , dec=.) SD-sd(as.numeric(Matrix)) SD First, your data attachment did not come through the list. Second, decimals are not a problem. Third, you don't have a matrix, you have a data frame (read.table produces data frames). As long as all columns are numeric you could do something like sd(c(as.matrix(m))) You could also convert to a matrix on input if you really don't need a dataframe for different column types. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with random number simulation
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Petr PIKAL Sent: Monday, July 25, 2011 9:05 AM To: AriGold Cc: r-help@r-project.org Subject: Re: [R] Problem with random number simulation Hi r-help-boun...@r-project.org napsal dne 25.07.2011 05:23:51: Re: [R] Problem with random number simulation Hi, I was just hoping someone could try running the program to see if they get any output. This is independent research. I just need to run this simulation to see how a computer could be manipulated given certain conditions in the Von Neumann game. Currently, my code is not giving any errors, but there is no output either. I type x afterwards and nothing happens. I got many errors the first one is + { + if(y[count]lt;a) Error: unexpected ';' in: { if(y[count]lt; { + And it is really difficult to debug such code in R. Maybe you could put it in a function and try ?debug to see what values you get in each line of code Regards Petr I can add comments but I don't know how to edit the original post. I don't use Nabble, and I think that is the case for most of the people that _I_ find to be most knowledgeable and helpful. When replying from Nabble, I think posts can be quoted, and comments could be added at that point. Another problem with Nabble is that it sends HTML by default (I think), which is not appropriate for this list. At least, that is the problem that Petr ran into above. The error message that he ran into was due to a less than sign being sent as an html equivalent, LT; , which obviously R will choke on. Again, if the OP would follow the posting guide and provide commented, minimal, self-contained, reproducible code (that includes no HTML), someone may be willing and able to help. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with random number simulation
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Nordlund, Dan (DSHS/RDA) Sent: Monday, July 25, 2011 10:39 AM To: r-help@r-project.org Subject: Re: [R] Problem with random number simulation snip I don't use Nabble, and I think that is the case for most of the people that _I_ find to be most knowledgeable and helpful. When replying from Nabble, I think posts can be quoted, and comments could be added at that point. Another problem with Nabble is that it sends HTML by default (I think), which is not appropriate for this list. At least, that is the problem that Petr ran into above. The error message that he ran into was due to a less than sign being sent as an html equivalent, LT; , which obviously R will choke on. Again, if the OP would follow the posting guide and provide commented, minimal, self- contained, reproducible code (that includes no HTML), someone may be willing and able to help. Upon reading my own post, I realized that I left out a phrase that made it read like I was denigrating the knowledge and helpfulness of anyone using Nabble. That was not my intent. I intended to write I don't use Nabble, and I think that is the case for most of the people _on R-help_ that _I_ find to be most knowledgeable and helpful. There may well be some very knowledge and helpful people posting to R-help from Nabble, but the people whose posts I regularly read don't happen to use Nabble. And there have been a few posts of late where people posting from Nabble either don't care to, or can't figure out how to follow the posting guidelines when using Nabble. 'Nuff said. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Taking all complete diagonals of a matrix
-Original Message- From: Peter Lomas [mailto:peter.lo...@ucalgary.ca] Sent: Tuesday, July 19, 2011 6:42 PM To: Nordlund, Dan (DSHS/RDA) Cc: r-help@r-project.org Subject: Re: [R] Taking all complete diagonals of a matrix Thanks very much to everyone who replied. Peter got me on my way with the use diag() hint, and I came with a less pretty version of Dan's first option almost at the same time as I got that email. Seems I can't avoid one for loop, but one is better than two. Just as a note, with this code you have to make sure that you are in fact giving it a matrix, or diag() will error. I fed it a data frame unaware, but using as.matrix() works just fine. diagonals - function(mat){ R - dim(mat)[1] C - dim(mat)[2] output - matrix(NA,(R-C+1),C) for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } example - rbind(rep(1,3),rep(2,3),rep(3,3),rep(4,3),rep(5,3)) diagonals(as.data.frame(example)) Error in output[i, ] - diag(mat[i:(i + C - 1), ]) : number of items to replace is not a multiple of replacement length Thanks again, Peter On Tue, Jul 19, 2011 at 17:34, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Peter Lomas Sent: Tuesday, July 19, 2011 2:16 PM To: r-help@r-project.org Subject: [R] Taking all complete diagonals of a matrix snip Peter, Here are two possibilities. I leave it up to you to determine whether they are cleaner or faster. diagonals1 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } diagonals2 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[,i] - mat[i:(i+C-1),i] return(output) } Hope this is helpful, Peter, I am not sure what happened with the diagonals2 function that I posted yesterday (which I thought I had tested and it worked) because it clearly doesn't work. Here is a revised version that does work and is faster than using the diag() function. It will also work fine with a data frame as input. diagonals2 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:C) output[,i] - mat[i:(i+R-C),i] return(output) } Hope this is more helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] calculating the mean of a random matrix (by row) and some general questions
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of RichardLang Sent: Tuesday, July 19, 2011 11:44 AM To: r-help@r-project.org Subject: [R] calculating the mean of a random matrix (by row) and some general questions Hi everyone! I'm trying to teach myself R in order to do some data analysis. I'm a mathematics student and (only) familiar with matlab and latex. I'm working trough the official introduction to R at the moment, while simultaneously solving some exercises I found in the web. Before I post my (probably stupid) question, I'd like to ask you for some general advice. How do you work with R? Is it like in matlab, that you write your functions with a lot of loops etc. in a textfile and then run it? Or do you just prepare your data and then use the functions provided by R (plot, mean etc) to get some analysis? I'd be very thankfull for some of your thoughts about approaches. Now the question: I'm trying to build a vector with n entries, each consisting of the mean of m random numbers (exponential distributed for example). My approach was to construct a nxm random matrix and then to somehow take the mean of each row. But in the mean function there is no parameter to do this, so the intended approach of R is probably different.. any ideas? =) Richard Richard, If you have a matrix, M, with n rows and m columns, you can use the apply() function to get either row or column means n - 10 m -3 M - matrix(rnorm(m*n),n,m) M [,1][,2] [,3] [1,] 0.6239267 -0.70546496 0.3682918 [2,] -0.7326689 -1.86571052 -0.2899552 [3,] 0.7778313 -1.01227191 0.7735718 [4,] 0.8336683 -0.07755214 -0.1375798 [5,] -1.6134414 0.12088648 -0.4064939 [6,] -0.2578007 0.45142456 -1.0197297 [7,] 1.0108260 -0.24933408 -0.4083304 [8,] -0.7936603 -0.67286769 -0.8666802 [9,] 1.0054039 2.52498995 1.0915742 [10,] -0.1610073 0.43504924 2.4288474 rowMeans - apply(M,1,mean) rowMeans [1] 0.09558452 -0.96277820 0.17971042 0.20617876 -0.63301628 -0.27536860 [7] 0.11772050 -0.3605 1.54065601 0.90096312 colMeans - apply(M,2,mean) colMeans [1] 0.06930777 -0.10508511 0.15335160 I will let others describe how they use R. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Taking all complete diagonals of a matrix
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Peter Lomas Sent: Tuesday, July 19, 2011 2:16 PM To: r-help@r-project.org Subject: [R] Taking all complete diagonals of a matrix Hi R-Help! I am trying to find a nicer way of extracting all the complete diagonals of a matrix. I am working with very large matrices that have many more rows than columns. I want to be able to extract each of the diagonals that are as long as the number of columns in the matrix. I have written a rather ugly function that presently does the job. It illustrates what I am trying to do, but I feel like there must be a cleaner (and faster) way. Does anybody have any ideas? Here is what I've done so far: diagonals - function(mat){ output - matrix(0,(dim(mat)[1]-dim(mat)[2]+1),NCOL(mat)) for(i in 1:NROW(output)){ G - c() for(j in 1:NCOL(mat)){ G - c(G,mat[(i+j-1),j]) } output[i,] - G } return(output) } example - rbind(rep(1,3),rep(2,3),rep(3,3),rep(4,3),rep(5,3)) example [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]444 [5,]555 diagonals(example) [,1] [,2] [,3] [1,]123 [2,]234 [3,]345 Many thanks, Peter Peter, Here are two possibilities. I leave it up to you to determine whether they are cleaner or faster. diagonals1 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } diagonals2 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[,i] - mat[i:(i+C-1),i] return(output) } Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Import big xml data
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of David Winsemius Sent: Wednesday, July 13, 2011 8:17 AM To: Sebastian Kruk Cc: r-help@r-project.org Subject: Re: [R] Import big xml data On Jul 13, 2011, at 8:09 AM, Sebastian Kruk wrote: Dear R users, I would like to import a big xml file. I don't want to learn about xml structures, just to import all the data to a data frame. How can I do it? I am reminded of this: library(fortunes) fortune(brain surgery) But, just in case the OP is willing to at least learn a little about how to deal with XML files, he could download and install the sos package. Then library(sos) findFn('XML') found 686 matches; retrieving 20 pages, 400 matches. So there are lots of packages and functions to choose from. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Latent Transition Analysis in R ?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of David Joubert Sent: Wednesday, July 13, 2011 9:55 AM To: r-help@r-project.org Subject: [R] Latent Transition Analysis in R ? Are there any packages in R that allow for estimation of LTA models ? Thank you, David Joubert [[alternative HTML version deleted]] Well, I Googled 'latent transition analysis R', and the very first hit led me here https://www.msu.edu/~chunghw/downloads.html So, there is R code available for doing LTA. I can't speak to the issue of quality or usability because I haven't used it. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Contributed Packages - Hmisc survey
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Muhuri, Pradip (SAMHSA/CBHSQ) Sent: Wednesday, June 01, 2011 1:01 PM To: 'r-help-requ...@r-project.org'; 'R-help@r-project.org' Subject: [R] Contributed Packages - Hmisc survey Hello List, Could someone tell why I can't install the Himsc and survey packages for R version 2.13.0 (2011-04-13)? What am I doing wrong here? Thanks, Pradip install.packages (Hmisc, dependencies=TRUE) --- Please select a CRAN mirror for use in this session --- Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'Hmisc' is not available (for R version 2.13.0) install.packages (survey, dependencies=TRUE) Warning: unable to access index for repository http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/2.13 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package 'survey' is not available (for R version 2.13.0) I get a 502 Bad Gateway error when I try to go to that mirror. Maybe it is down. Have you tried another mirror? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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-2.10.1 to R-2.13.0
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of ogbos okike Sent: Thursday, May 26, 2011 7:42 AM To: Steve Lianoglou Cc: r-help@r-project.org Subject: Re: [R] R-2.10.1 to R-2.13.0 Hi Steve, Many thanks. I added :deb http://cran.at.r-project.org/bin/linux/ubuntu lucid/ in my source.list and then tried sudo apt-get update. The last lines of the result says: Reading package lists... Done W: GPG error: http://cran.at.r-project.org lucid/ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 51716619E084DAB9 I am in south africa. I looked at the cran mirrors, there is no south africa. I chose Australia. Thanks for more help. Regards Ogbos On 26 May 2011 16:13, Steve Lianoglou mailinglist.honey...@gmail.comwrote: Hi, On Thu, May 26, 2011 at 10:05 AM, ogbos okike ogbos.ok...@gmail.com wrote: Hi Duncan, Thanks for your time. Using ./configure as specified in the installation manual, I attempted to install R-2.13.0 but it reported an error message: checking for IceConnectionNumber in -lICE... no checking X11/Intrinsic.h usability... no checking X11/Intrinsic.h presence... no checking for X11/Intrinsic.h... no configure: error: --with-x=yes (default) and X11 headers/libs are not available Could you please advise further. I am attempting this for the first time on my laptop (ubuntu os). Can you just follow the instructions here: http://cran.cnr.berkeley.edu/bin/linux/ubuntu/ And use the apt-get mechanism to install R instead of compiling it yourself? I'm guessing it'd make your life a bit easier. -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact [[alternative HTML version deleted]] Well, it looks like you didn't read far enough in the instructions that you were pointed towards. Read the section on Secure APT. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Fibonacci
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of David Winsemius Sent: Thursday, April 21, 2011 8:44 AM To: Michael Dewey Cc: r-help@r-project.org Subject: Re: [R] Fibonacci On Apr 21, 2011, at 9:04 AM, Michael Dewey wrote: At 10:42 20/04/2011, Georgina Imberger wrote: Hi! I am trying to work out the code to get a Fibonacci sequence, using the while() loop and only one variable. And I can't figure it out. phi - 0.5 * (1 + sqrt(5)) phi [1] 1.618034 fib - function(n) {(phi ^ n - (1 - phi) ^ n) / sqrt(5)} fib(1:10) [1] 1 1 2 3 5 8 13 21 34 55 Admittedly this does not use a while loop as you requested I like it! test -c( 1, 1, 2, 3, 5, 8, 13, 21, 34, 55) test == fib(1:10) [1] TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE To avoid such FAQ-tual puzzlement, it might be better to round to zero digits: fib2 - function(n) {round( (phi ^ n - (1 - phi) ^ n) / sqrt(5) ) } test == fib2(1:10) [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE There are several packages that offer fib() functions of one name or another, including the gmp package which always seems to think bigger than I do. I cannot (trivially) see how that author does it with fibnum(), because it is in a .Call() -- David Courtesy of Wikipedia Fibonacci-c(1,1) while (max(Fibonacci)500){ Fibonacci-c(Fibonacci, (max(Fibonacci) + ?(Fibanacci))) } How can I tell R to take the value one before the max value? (Without defining another variable) (Probably super easy... I am a beginner...) Thanks, Georgie [[alternative HTML version deleted]] Michael Dewey i...@aghmed.fsnet.co.uk http://www.aghmed.fsnet.co.uk/home.html I, too, like the Michael/David/Wikipedia solution. But if this is homework, I would recommend using length() instead of max() for getting the last two items of the vector. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] identical values not so identical? newbie help please!
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of maiya Sent: Thursday, March 10, 2011 7:19 AM To: r-help@r-project.org Subject: [R] identical values not so identical? newbie help please! Hi there! I'm not sure I can create a minimal example of my problem, so I'm linking to a minimal .RData file that has only two objects: obs and exp, each is a 6x9 matrix. http://dl.dropbox.com/u/10364753/test.RData link to dropbox file (I hope this is acceptable mailing list etiquette!) Here's what happens: obs[1, 1] [1] 118 exp[1, 1] [1] 118 obs[1, 1]-exp[1, 1] [1] 2.842171e-14 Problem is, both obs and exp should be identical. They are the result of a saturated loglinear model, and I've run the same code across about 400 tables, all of which result in sum(obs-exp)=0, except for this one. I can't figure it out? Anyway, I need help understanding why 118 and 118 are not really the same. I appreciate some may be wary of downloading my .Rdata file (I'm on ubuntu if that's any consolation), but I don't know how else to ask this quesiton! Thanks! Maja Z. See the R FAQ 7.31 Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] identical values not so identical? newbie help please!
Maja, Isn't modern technology wonderful? With computers we are able to do calculations that we could never do by hand, and we get to complain about the results not being exact. :-) More comments below -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of maiya Sent: Thursday, March 10, 2011 10:34 AM To: r-help@r-project.org Subject: Re: [R] identical values not so identical? newbie help please! Thanks Josh and Dan! I did figure it had something to do with the machine epsilon... But so what do I do now? I'm calculating the total absolute error over thousands of tables e.g.: tae-sum(abs(obs-exp)) Is there any easy way to I keep these ignorable errors from showing up? No, there is no easy way. And furthermore, why does this happen only sometimes? The two (2D) tables I attached are actually just one 'layer' in a 3D table. And only 2 out of about 400 layers had this happen, all the other ones are identical - perfectly! And out of 2000 3D tables, about 60 of which should have no error, only 10 actually show an error of zero, and in the rest this same thing happens in a few layers. It could be a function of the order in which calculations occur, or the fact that results of calculations can be represented exactly sometimes and not others. OK, this is a bit messy for a real question. I mean I can just round down all the errors that are under 1e-8 or something, but I'd much rather this not happen in the first place? The only way to prevent this is to use infinite precision calculations. I don’t pretend to be an expert in numerical analysis, but is the accumulation of a small number of errors, each on the order of 10^-14, going to affect your absolute error appreciably? (I know we all prefer exact.) Thanks again to the two posters for bothering with me! Maja. Maybe someone else will have more encouraging advice. Good luck. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 - Error in as.vector(x, mode)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Arne Henningsen Sent: Thursday, March 10, 2011 12:09 PM To: Alex Olssen; r-help@r-project.org Subject: Re: [R] R beginner - Error in as.vector(x, mode) Dear Alex On 10 March 2011 20:31, Alex Olssen alex.ols...@gmail.com wrote: I find it hard to provide a reproducible version of this error. When I use the exact same procedure but get data from data() everything works fine. I.e., I do not think the startvals are the problem - in fact I copied the syntax for the startvals directly from the example in the documentation which does work. The following code is very similar to my code above. The important difference is the way the data is obtained. This code works. library(systemfit) library(foreign) data(mtcars) eqDrat - drat ~ a0 + a1*mpg + a2*qsec eqWt - wt ~ b0 + b1*mpg + b2*qsec model - list(eqDrat, eqWt) start.values - c(a0=0.5, a1=0.5, a2=0, b0=0.5, b1=0.5, b2=0) nlsystemfit(OLS, model, start.values, data = mtcars) I think I could solve my problem if I could use my data through data() instead of through read.table() Does anyone know if this is possible? I tried to send this response from my phone, but no luck. :-( Anyway, in the OP's original post, the call to nlsystemfit used data=auto, i.e. nlsystemfit(OLS, model, start.values, data = auto) instead of data=auto74. Could that be the source of the problem? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating a weighted sample - Help
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of LouiseS Sent: Thursday, March 03, 2011 5:21 AM To: r-help@r-project.org Subject: Re: [R] Creating a weighted sample - Help Hi Thanks for responses. The sample I have taken is a random sample from H, I, J and K. The further analysis I want to do is all around bad debt rates so it could be (H/H+I)*100 = Bad rate percentage also population stability calculations that are all related to credit scoring. I want to be able to report back on any variable that I have in my data set based on my factored counts (A) of 10,000 - so every calculation is based on 10,000 account in the correct proportions. Does his help? Thanks once again Louise Louise, It appears that you have done a stratified random sample of four types of accounts and have oversampled the less frequent account types. You definitely should consider doing your analyses using the survey package (or similar package) that appropriately accounts for the sampling variability. Otherwise, your variances / standard errors are going to be incorrect. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Difference in numeric Dates between Excel and R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Luis Felipe Parra Sent: Tuesday, March 01, 2011 3:07 PM To: r-help Subject: [R] Difference in numeric Dates between Excel and R Hello. I am using some dates I read in excel in R. I know the excel origin is supposed to be 1900-1-1. But when I used as.Date with origin=1900-1- 1 the dates that R reported me where two days ahead than the ones I read from Excel. I noticed that when I did in R the following: as.Date(2011-3-4)-as.Date(1900-1-1) Time difference of 40604 days but if I do the same operation in Excel the answer is 40605. Does anybody know what can be going on? I think so. It is a known problem that Excel thinks 1900 was a leap year, but it was not. So Excel counts an extra day (for nonexistent Feb 29, 1900). In addition, Excel considers 1900-01-01 as day 1, not day 0. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] convert the sas file into csv in R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of yf Sent: Thursday, February 17, 2011 2:35 PM To: r-help@r-project.org Subject: [R] convert the sas file into csv in R i am trying to convert sas file into csv. I used write.csv(a, file=cool.csv) but nothing come out. i don't know why. Thanks. library(Hmisc) a- sasxport.get(C:\\Users\.) write.csv(a, file=cool.csv) What do you mean nothing come out? Where did you look for the file? It should have been written to your current working directory. You might try specifying a complete path so you know where you expect to find the CSV file. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] FP growth in R?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of robert tibshirani Sent: Tuesday, February 08, 2011 10:16 AM To: r-help@r-project.org Subject: [R] FP growth in R? Does anyone know of an R interface to Christian Borgelt's implementation of the FP growth algorithm? thanks a lot Rob Tibshirani -- I get so much email that I might not reply to an incoming email, just because it got lost. So don't hesitate to email me again. The probability of a reply should increase. Prof. Robert Tibshirani Depts of Health Research and Policy, and Statistics Stanford Univ Stanford CA 94305 t...@stanford.edu http://www-stat.stanford.edu/~tibs A quick Google search found this link where the FP growth algorithm and Borgelt are discussed in the context of datamining with R http://en.wikibooks.org/wiki/Data_Mining_Algorithms_In_R/Frequent_Pattern_Mining/The_FP-Growth_Algorithm#FP-Growth_Algorithm_Variations Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] p value for joint probability
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of moleps Sent: Tuesday, February 01, 2011 11:32 AM To: Peter Ehlers Cc: r-help@r-project.org Subject: Re: [R] p value for joint probability My terminology is probably way off. I´ll try again in plain english. I´d like to generate a scatter plot of r1 r2 and color code each pair according to the probability of observing the pair given that the two samples (r1 r2) are drawn from two independent normal distributions. rr-data.frame(r1=-rnorm(1000,10,5),r2=-rnorm(1000,220,5)) with(rr,plot(r1,r2)) Best, //M And the answer is the same as Peter gave below. The theoretical probability of a specific pair of numbers occurring in your example is zero. So, I will ask Peter's question differently (although his question was a good one). What is your interest in doing these plots? What are you trying to understand? Are you just trying to learn how do this joint probability plot for use on data where there is a non-zero probability of pairs of numbers occurring? Equiring minds would like to know. :-) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 On 31. jan. 2011, at 23.13, Peter Ehlers wrote: On 2011-01-31 12:42, moleps wrote: Dear all, Given rr-data.frame(r1-rnorm(1000,10,5),r2-rnorm(1000,220,5)) How can I add a column (rr$p) for the joint probability of each r1 r2 pair? If you take the values in each pair to be observations from two independent Normal distributions, it's easy: The joint probability of those values is zero. But I suspect you mean something else by joint probability. Can you elaborate? Peter Ehlers I know how to add the column.. I just dont know how to compute the p value for joint probabilities given the two samples. //M __ 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] There must be a smarter way
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of eric Sent: Thursday, January 27, 2011 7:07 PM To: r-help@r-project.org Subject: [R] There must be a smarter way Newbie and trying to learn the right way of doing things in R. in this case, I just have that feeling that my convoluted line of code is way more complicated than it needs to be. Please help me in seeing the easier way. I want to do something pretty simple. I have a dataframe called x that is 6945 elements long. I'd like to create a vector rtn= log(x[2,2]/x[1,3]), then log(x[3,2]/x[2,3]), then log(x[4,2]/lx[3,3]) ...log(x[6945,2]/x[6944,3]). Also want to put zero as the first element. I know I can do it with a loop but I'd like to figure out the simple way to vectorize it. Here's my solution (it works but it's sure complicated looking) : rtn -c(0,log(x[2:length(x[,1]),2]/x[1:length(x[,1])-1,3])) Here's what x looks like: head(x) Date Open Close 1 03/30/1983 29.96 30.35 2 03/31/1983 30.35 30.24 3 04/04/1983 30.25 30.39 4 04/05/1983 30.45 30.66 5 04/06/1983 30.85 30.85 6 04/07/1983 30.85 31.12 How about something like rtn -c(0,log(x[-1,2]/x[-6945,3])) or if you want to allow for unknown length, then rtn -c(0,log(x[-1,2]/x[-nrow(x),3])) hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] sensitivity logical operators in R
Marc You have been given the answer already and a solution. See the R FAQ 7.31. As you have discovered this issue is not specific to R. In order to eliminate this problem entirely, you will need a computer system with infinite precision. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Marc Jekel Sent: Monday, January 24, 2011 11:48 AM Cc: r-help@r-project.org Subject: Re: [R] sensitivity logical operators in R Hi again, I have checked the same code (see below) using MATLAB. It produces the same error (i.e., equal numbers are evaluated as unequal). Do I miss something? Thanks for help! Marc Marc Jekel schrieb: Hello R Fans, Another question for the community that really frightened me today. The following logical comparison produces a false as output: t = sum((c(.7,.69,.68,.67,.66)-.5)*c(1,1,-1,-1,1)) tt = sum((c(.7,.69,.68,.67,.66)-.5)*c(1,-1,1,1,-1)) t == tt This is really strange behavior. Most likely this has something to do how R represents numbers internally and the possible sensitivity of a computer? Does anyone know when this strange behavior occurs and how to fix it? Thank you all! This list is pleasure!!! Marc __ 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] sample() issue
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of cory n Sent: Monday, December 20, 2010 11:04 AM To: r-help@r-project.org Subject: [R] sample() issue length(sample(25000, 25000*(1-.55))) [1] 11249 25000*(1-.55) [1] 11250 length(sample(25000, 11250)) [1] 11250 length(sample(25000, 25000*.45)) [1] 11250 So the question is, why do I get 11249 out of the first command and not 11250? I can't figure this one out. Thanks Cory See FAQ 7.31 Then try .45 == (1-.55) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] longer object length is not a multiple of shorter object length
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of madr Sent: Tuesday, December 07, 2010 3:02 PM To: r-help@r-project.org Subject: [R] longer object length is not a multiple of shorter object length In datamatrix[, y] == datamatrix[, y][-1] : longer object length is not a multiple of shorter object length out = c(FALSE,datamatrix[,'y'] == datamatrix[,'y'][-1]) and I do not know why I get that error, the resulting out matrix is somehow one row larger than datamatrix... all I try to do is filter matrix by dropping rows where [,'y'][-1] == [,'y'][+1] If I understand what you want correctly, something like this may give you what you want # create data fraome to work with x - 1:10 y - c(2, 2, 4, 3, 5, 5, 4, 1, 2, 5) df - data.frame(x,y) # out contains rows to drop out out - which(c(FALSE, df[-1,'y'] == df[-nrow(df), 'y'])) df[-out,] # keep contains rows to keep keep - which(c(TRUE, df[-1,'y'] != df[-nrow(df), 'y'])) df[keep,] Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 can I refer to actual (n) and previous (n-1) elements in a vector?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Marianne Stephan Sent: Monday, December 06, 2010 9:13 AM To: r-help@r-project.org Subject: [R] How can I refer to actual (n) and previous (n-1) elements in a vector? Hello, How can I apply a function on a vector that refers to actual (n) and previous elements in the vector (e.g. n-1)? For example: I would like to calculate the sum of (n-1) + n for each element of a vector and get a vector as a result. Besides others I tried this: v-c(3,6,8,1,1,3,9,5,6,3) for (i in 1:NROW(v)){a[i]-a[i-1]+a[i]} I would like to get this result: 9,14,9,2,4,12,14,11,9 I would greatly appreciate your help! Marianne [[alternative HTML version deleted]] How about something like v[-n] + v[-1] Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 can I refer to actual (n) and previous (n-1) elements in a vector?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Nordlund, Dan (DSHS/RDA) Sent: Monday, December 06, 2010 9:21 AM To: r-help@r-project.org Subject: Re: [R] How can I refer to actual (n) and previous (n-1) elements in a vector? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Marianne Stephan Sent: Monday, December 06, 2010 9:13 AM To: r-help@r-project.org Subject: [R] How can I refer to actual (n) and previous (n-1) elements in a vector? Hello, How can I apply a function on a vector that refers to actual (n) and previous elements in the vector (e.g. n-1)? For example: I would like to calculate the sum of (n-1) + n for each element of a vector and get a vector as a result. Besides others I tried this: v-c(3,6,8,1,1,3,9,5,6,3) for (i in 1:NROW(v)){a[i]-a[i-1]+a[i]} I would like to get this result: 9,14,9,2,4,12,14,11,9 I would greatly appreciate your help! Marianne [[alternative HTML version deleted]] How about something like v[-n] + v[-1] Sorry for the noise. That should have been v[-length(v)] + v[-1] Hope this is more helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 this SAS transport file in R?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of zhiji19 Sent: Sunday, December 05, 2010 9:26 PM To: r-help@r-project.org Subject: [R] How to this SAS transport file in R? Dear All, I try to read the SAS transport file in R, but it shows error. Please help! I am using R 2.11.1 library(foreign) download.file(http://isites.harvard.edu/fs/docs/icb.topic35387.files/d emo_c.xpt,C:/Desktop/demo_c.xpt) sasxport - read.xport(C:/Desktop/demo_c.xpt) Error in lookup.xport(file) : file not in SAS transfer format I think You need to use mode='wb' in your download statement download.file(http://isites.harvard.edu/fs/docs/icb.topic35387.files/demo_c.xpt;, C:/Desktop/demo_c.xpt, mode='wb') Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Filter data
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Diogenas Sent: Thursday, December 02, 2010 12:09 PM To: r-help@r-project.org Subject: [R] Filter data Hello, I understand that question is probably stupid, but ... I have data (polity IV index) country,year,democ,autoc,polity,polity2 1,Afghanistan ,1800,1,7,-6,-6 2,Afghanistan ,1801,1,7,-6,-6 3,Afghanistan ,1802,1,7,-6,-6 I need to create new data sets which includes only cases after year 1995. I've tried this command: poli2-poli[poli$year 1994,] , however it generated this: Error in poli[poli$year 1994, ] : incorrect number of dimensions. Any ideas how i can overcome this? We need more information. You haven't given us a self-contained, reproducible example. The syntax you show works for me. What does str(poli) show? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Outlier statistics question
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jahan Sent: Tuesday, November 30, 2010 12:16 PM To: r-help@r-project.org Subject: [R] Outlier statistics question I have a statistical question. The data sets I am working with are right-skewed so I have been plotting the log transformations of my data. I am using a Grubbs Test to detect outliers in the data, but I get different outcomes depending on whether I run the test on the original data or the log(data). Here is one of the problematic sets: fgf2p50=c(1.563,2.161,2.529,2.726,2.442,5.047) stripchart(fgf2p50,vertical=TRUE) #This next step requires you have the 'outliers' package library(outliers) grubbs.test(fgf2p50) #the output says p0.05 so 5.047 is an outlier #Next, I run the test on the log(data) log10=c(0.194,0.335,0.403,0.436,0.388,0.703) grubbs.test(log10) #output is that p0.05 so we reject that there is an outlier. The question is, which outlier test do I accept? You may not want to accept either test. What do YOU mean by an outlier, and why is it important for you to detect and handle outliers differently? Maybe you should model the data so that the model correctly predicts or explains the so-called outlier. So, what is it that you are wanting to do? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Running R from SAS
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of ziad.elmou...@tnsglobal.com Sent: Wednesday, November 24, 2010 3:27 AM To: r-help@r-project.org Subject: [R] Running R from SAS Hello All, I am interested in running an R program with several random seeds. One approach is to launch the program from SAS. The recommended approach is to use the X command as shown below: OPTIONS XWAIT XSYNC; X r.exe --no-save --quiet c:\temp\r\program.r c:\temp\r\program.log; However, this does not seem to work for me. Does anyone know how to launch an R program from SAS? Thank you in advance. Ziad Elmously ziad.elmou...@tnsglobal.com You haven't given enough information for anyone to offer you anything more than educated guesses. What do you mean this does not seem to work for me? What error messages are you getting. If you want to run R from SAS (or any other program) you need to figure out what command will work from the command line. I assume your unstated OS is some version of MS Windows. What version of R? Is R.exe in your path? If not you need either need to add the path to SAS to your PATH environment variable, or you need to give the full path in the x command. Try entering your command at the windows command prompt (you have no spaces in your filenames/paths so the quotes aren't necessary) R --no-save --quiet c:\temp\r\program.r c:\temp\r\program.log If the command doesn't work then let us know what the errors are. This is the syntax I sometimes use on my machine: x 'c:\R\R-2.12.0\bin\x64\R.exe --vanilla c:\SAS_examples\run_R_from_SAS_test.R c:\SAS_examples\run_R_from_SAS_test.out'; Since I have R in my PATH, I could have just used x 'R --vanilla c:\SAS_examples\run_R_from_SAS_test.R c:\SAS_examples\run_R_from_SAS_test.out'; I could have also used Rcmd BATCH like this; x 'Rcmd BATCH --vanilla c:\SAS_examples\run_R_from_SAS_test.R'; and the output would be placed in c:\SAS_examples\run_R_from_SAS_test.Rout automatically. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 program an error into an if-then statement
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Dimitri Liakhovitski Sent: Tuesday, November 09, 2010 8:56 AM To: r-help Subject: [R] How to program an error into an if-then statement Hello! I am running a loop (for a range of dates) and in this loop I am reading in different files - based on a date that is part of the file name. However, for some of the dates, I have no file (no way to know which dates). So, when I try to read it in I get an error: Error in file(file, rt) : cannot open the connection Question: I'd like to program an if-then statement in my code that says something like this: myfile-read.csv(myfilename) if cannot open the connection - then do X What statement should I use under if? Thanks a lot! Rather than trying to read a non-existent file and generating an error, you might want to check if the file exists before trying to read it and take your alternative action if it doesn't exist. Check out ?file.exists Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Centre of gravity of a mountain
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Peter Langfelder Sent: Tuesday, November 09, 2010 3:49 PM To: Barry Rowlingson Cc: r-help@r-project.org; Ab Hu Subject: Re: [R] Centre of gravity of a mountain On Tue, Nov 9, 2010 at 3:40 PM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: On Mon, Nov 8, 2010 at 5:15 PM, Peter Langfelder peter.langfel...@gmail.com wrote: If you also need the z coordinate, it simply the mean of the matrix Z. zCenter = mean(Z) How can that be right? Suppose your mountain is very flat, so that your mountain is effectively a cube. The Z values are all the same, and so their mean is the same. However the centre of mass is, by symmetry, clearly at height/2. Similarly suppose your mountain matrix is one large cell value and all the rest are near zero - the mean Z will be close to zero but the centre of mass will be almost half way up the single cell value, because all the near-zeros contribute nothing to the centre of mass position. Yup, the z coordinate is wrong. Only the x and y are right. Peter I believe that should have been mean(z)/2 Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] count occurrence and distance of characters in string
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Immanuel Sent: Thursday, November 04, 2010 3:42 PM To: r-help@r-project.org Subject: [R] count occurrence and distance of characters in string Hello all, I want to know how often one character occurs in a given string and the distance from between every two occurences. (distance = other characters between them). thanks Without a reproducible example, I can only guess. But this should get you started. s - 'abcdeabcxdeabcdeaxabcdeabcdeabcdxeabc' chr.pos - which(unlist(strsplit(s,NULL)) == 'x') chr.count - length(chr.pos) chr.dist - diff(chr.pos)-1 chr.pos chr.count chr.dist Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] doubt in climate variability analysis in R! - code included!
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of govin...@msu.edu Sent: Friday, October 29, 2010 11:56 AM To: r-help@r-project.org Subject: Re: [R] doubt in climate variability analysis in R! - code included! the following code was used library(akima) library(clim.pact) nc.1 - RF_80-05.nc nc.rf.in - open.ncdf(nc.1) x1 - retrieve.nc(nc.1, v.nam=Rainfall,l.scale=FALSE, x.rng=c(70, 80), y.rng=c(10, 13.5)) #dimension is checked for the subset. (lon, lat, time) is changed as (time, lat, lon) dim(x1$dat) #[1] 2192 8 20 My question is - how can i convert this array into a dataframe so that i have lat, lon, precipitation values in 3 different columns (note, I will have it for just a single day). So, my expected dataframe will have rainfall values for each given pair of lon and lat. Or is there any other better way to do my spatial variogram analysis for a single day given the above dataset? here is the link for the dataset. HTTP://WWW.4SHARED.COM/FILE/4ZV0G3JR/RF_80-85.HTML The link to the data did not work, so we still don't have a self-contained, reproducible example. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 exporting data using write.foreign
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Andrew Miles Sent: Wednesday, October 20, 2010 10:10 AM To: r-help@r-project.org Subject: [R] Problem exporting data using write.foreign My question is about the write.foreign() command in the foreign package. I use a command like the following to try and output data and a code file to read my data into SAS. write.foreign(data.frame.object, datafile=filepath, codefile=filepath, package=SAS, dataname=myData) With my data set, it gives the following error: Error in make.SAS.names(names(df), validvarname = validvarname) : Cannot uniquely abbreviate the variable names to 32 or fewer characters I tried to write reproducible code but could not. I'm not sure where to go from here. What are the naming protocols for variables so that they can be exported using write.foreign()? Thanks! Andrew Miles Well, the error message tells you that the names must be unique when truncated to 32 characters. Apparently, you have at least 2 variables that have the same name when truncated to 32 characters. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] repeat a function
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Michael Bedward Sent: Wednesday, September 29, 2010 5:34 PM To: Michael Larkin; Rhelp Subject: Re: [R] repeat a function On 30 September 2010 02:48, Michael Larkin mlar...@rsmas.miami.edu wrote: testdat - replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE) ] ) I can't seem to get it to work. I keep getting the error message of undefined columns selected Any advice? Michael, As has been pointed out, you seem to be trying to reinvent the wheel. But to answer your question, you need a comma just before the final square bracket. Then you need to set the simplify=FALSE parameter for the replicate function. So something like this testdat - replicate( 50, growth[sample(nrow(growth), 8, rep=TRUE),], simplify=FALSE) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Length of vector without NA's
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Joshua Wiley Sent: Thursday, September 23, 2010 8:23 AM To: Ralf B Cc: r-help Mailing List Subject: Re: [R] Length of vector without NA's Hi Ralf, The usual way (as others have shown you), takes advantage of the fact that the logical values TRUE and FALSE are counted as 1 and 0, respectively. is.na() returns TRUE if the value is NA, so to find how many are not NA, the result is reversed using ' ! '. Similar logic can be used to find how many meet any logical condition (e.g., sum(1:10 5) ). Cheers, Josh On Thu, Sep 23, 2010 at 8:08 AM, Ralf B ralf.bie...@gmail.com wrote: Hi, this following code: x-c(1,2,NA) length(x) returns 3, correctly counting numbers as well as NA's. How can I exclude NA's from this count? Ralf __ 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. Ralf, While I might use the sum() function as others have posted, if you want the code to clearly show your intent (i.e. to get the length of a vector) then another option is length(x[!is.na(x)]) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] import csv file problem
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of sisxy Sent: Wednesday, September 22, 2010 5:25 PM To: r-help@r-project.org Subject: [R] import csv file problem Hello, i am trying to import the csv file into R . i have a file saved as csv in my desktop. My laptop is Window vista, version R is 2.10.1. then i used the code Q-read.csv(Q.csv,header=TRUE) then my error is Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'Q.csv': No such file or directory i already search the previous solution i am confused , because some say for the file name is C:\\Q.csv so i change to xx-read.csv(C:\\desktop\\xx.csv,header=TRUE) but , Error in file(file, rt) : cannot open the connection In addition: Warning message: In file(file, rt) : cannot open file 'C:\desktop\xx.csv': No such file or directory any problem for my code ? any problem for the location of the file i saved or other possible problem that i dont know ? Really need urgent help ... thanks I presume you are working in some version of Windows OS. You have used several different paths to the file in your description above. What is the exact location of the file in Windows? Is it C:\q.csv C:\desktop\q.csv C:\desktop\xx.csv Or something else. Unless we know the exact name of the file and the directory in which it is located, there is not much we can do to help. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 convert a character into a filename?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Tucson August Sent: Tuesday, September 21, 2010 3:15 PM To: r-help@r-project.org Subject: [R] How to convert a character into a filename? Dear list, How to convert a character to a filename? such as: x - height # height here is actually a name of a colume in a data frame filename - paste(plant,x) write.csv (data, file=C:/plant/filename.csv) # having trouble with this statement, how to 'write' the filename here? All I want from above is to write 'data' to a file named plantheight.csv (the ultimate goal is to use a loop to transfer each column of a data frame into a separated file named from that column e.g. to create many files with different names but the names are all like: plantheight.csv, plantweight.csv, and height, weight.., are column names of a data frame) Thank you! Tuc Aug. For illustration purposes I will call your data frame, your.data . You can loop through the column names of your.data, construct an 'out' file name and then write the data. Something like for(i in names(your.data)){ out - paste(C:/plant/plant, i, .csv,sep=) write.csv(your.data[i], out, row.names=FALSE) } You didn't tell us whether you wanted row names witten to the file or not, so I decided not. Likewise, I decided to write column names (the default). Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Sas to R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Sarah Jilani Sent: Wednesday, September 15, 2010 10:44 AM To: r-help@r-project.org Subject: [R] Sas to R Hi, I need to call an R program from Sas. I have tried using the following code in Sas using the x command but it just calls up dos and says 'D:\Program' is not recognized as an internal or external command, operable program or batch file. ] SAS CODE: options xwait xsync; %let Rsource=S:\EPI_Data\Communicable Diseases\DR1355 Historic Communicable Disease Analaysis\R graphics; options xwait xsync; x 'D:\Program Files\R\R-2.9.2\bin\Rgui.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; What I need it to do is call R, run an R program and then go back to running sas. Any ideas on how to do that? Thanks! Sarah Sarah, I have found that making sure the command you wish to run will actually run at the command line is a big help. I suspect that the command, as you have specified it, will not run at the command line. Try copying everything inside the single quotes, open a command prompt, then paste the command and run it. I don't think it will do what you expect or want. That being said, try something like x 'D:\Program Files\R\R-2.9.2\bin\R.exe --no-save --quiet rsource.\Rtest.R rsource.\Rtest.log'; You don't want to run Rgui.exe, use R.exe. In addition, you don't want to double your double-quotes, because they are inside single-quotes. Doubling them will cause problems. If this doesn't work, then the R-help related issue is figuring out how to run R from the command line with input and output redirection. The syntax I provide above should run just fine in Windows XP/Vista/7. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 2.11, shell, spaces
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Oliver Soong Sent: Tuesday, September 07, 2010 2:01 PM To: R-lists Subject: [R] R 2.11, shell, spaces Can somebody confirm some unexpected behavior? This is under Windows, with R 2.11.0 and 2.11.1. 1. Create a trivial test file (I called it test.R) containing: cat(Success.\n) 2. Load R (Gui or Term) and run: shell(\C:\\path\\to\\Rscript.exe\ \C:\\path\\to\\test.R\) In my case, I get various error messages. If the path\\to\\Rscript.exe has spaces or not, it complains that the first token (e.g., 'C:\Program') is not a valid command. If the path\\to\\Rscript.exe has no spaces, it complains that the specified path is invalid. If C:\\path\\to\\test.R has no spaces, and I remove the surrounding quotes, things work as expected. I think this might be related to some earlier e-mail traffic that I didn't see a satisfactory resolution to. Cheers, Oliver The shell command is a user friendly wrapper for the system() command, that can sometimes introduce its own difficulties (for example your quoting problems). In addition, where you may need to include double quote marks for Windows purposes, I would use single quotes for the outer quotes in the R command. Try something like the following: system('C:\\path\\to\\Rscript.exe C:\\path\\to\\test.R') This works for me on R-2.11.1 running under Windows 7 (should work for other recent versions of R and Windows XP/Vista). I also prefer to use the forward slash for paths in R since it works in windows, reduces the typing (no need to escape them), and is compatible with Unix/Linux conventions. So, the following should work as well system('C:/path/to/Rscript.exe C:/path/to/test.R') Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] help - read SAS into R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of choonhong ang Sent: Tuesday, August 31, 2010 10:25 AM To: r-help@r-project.org Subject: [R] help - read SAS into R HI All, How to read SAS data directly into R ? Thank you You may or may not be able to depending on (1) what you mean by directly, (2) whether the SAS data is in a proprietary SAS dataset format or in a portable transport format, and (3) whether you have SAS available to run. Depending on your answers to the above questions you have the options of using the foreign package, Harrell's Hmisc package, the RODBC package, and probably some others. So, tell us about your particular situation, data format, availability of SAS, OS, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] read SAS dataset using read.ssd()
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Peter Dalgaard Sent: Monday, August 02, 2010 11:30 PM To: array chip Cc: r-help@r-project.org Subject: Re: [R] read SAS dataset using read.ssd() array chip wrote: Looks like the log file is not appropriately attached. Here it is again. Thanks for any suggestions. John Well, SAS isn't finding the file test in the SAS library .\Desktop, presumably because it has the wrong extension. The obvious question is whether you can read the .ssd01 file from SAS at all (I believe there's an Import menu somewhere). If you cannot, then R won't be able to help, if you can, there's an obvious workaround in saving it back as .sas7bdat. Peter is right that the file isn't found because of the extension. SAS datasets with a .ssd01 extension were created on a UNIX system (or maybe a MAC) and are not readable in the usual manner on a Windows system. Renaming the file is not going to work. The .ssd01 file needs to be converted to a transport file on the system on which it was originally created. Then it can be read using read.xport() from the foreign package. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Reset R environment through R command
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Ralf B Sent: Thursday, July 29, 2010 10:27 AM To: r-help@r-project.org Subject: Re: [R] Reset R environment through R command With environment I actually meant workspace. On Thu, Jul 29, 2010 at 1:22 PM, Ralf B ralf.bie...@gmail.com wrote: Is it possible to remove all variables in the current environment through a R command. Here is what I want: x - 5 y 10:20 reset() print(x) print(y) Output should be NULL for x and y, and not 5 and 10:20. Can one do that in R? Best, Ralf Ralf, You said you wanted to REMOVE the variables from the workspace, and you have received some good replies about how to do that. However, you then wrote: Output should be NULL for x and y, and not 5 and 10:20. Removing the variables is different from setting the variables to NULL. If you remove the variables and then try to print them, they won't output NULL. You will get an error message something like Error in print(x) : object 'x' not found So be forewarned if you actually wanted to set the values to NULL. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 generate a random data from a empirical distribition
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of xin wei Sent: Monday, July 26, 2010 11:36 AM To: r-help@r-project.org Subject: [R] how to generate a random data from a empirical distribition hi, this is more a statistical question than a R question. but I do want to know how to implement this in R. I have 10,000 data points. Is there any way to generate a empirical probablity distribution from it (the problem is that I do not know what exactly this distribution follows, normal, beta?). My ultimate goal is to generate addition 20,000 data point from this empirical distribution created from the existing 10,000 data points. thank you all in advance. Without knowing more than what you have stated in your email, I can only suggest that you look at ?sample You may be able to do something as simple as newdata - olddata[sample(1:1,size=2,replace=TRUE)] If you need more help, you need to tell us more about your data and what you are trying to do. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Question about a perceived irregularity in R syntax
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Peter Dalgaard Sent: Thursday, July 22, 2010 3:13 PM To: Pat Schmitz Cc: r-help@r-project.org Subject: Re: [R] Question about a perceived irregularity in R syntax Pat Schmitz wrote: Both vector query's can select the values from the data.frame as written, however in the first form assigning a value to said selected numbers fails. Can you explain the reason this fails? dat - data.frame(index = 1:10, Value = c(1:4, NA, 6, NA, 8:10)) dat$Value[dat$Value == NA] - 1 #Why does this fails to work, dat$Value[dat$Value %in% NA] - 1 #While this does work? #Particularly when str() results in an equivalent class dat - data.frame(index = 1:10, Value = c(1:4, NA, 6, NA, 8:10)) str(dat$Value[dat$Value %in% NA]) str(dat$Value[dat$Value == NA]) 1. NA and NA are very different things 2. checkout is.na() and its help page I also would have suggested is.na to do the replacement. What surprised me was that dat$Value[dat$Value %in% NA] - 1 actually worked. I guess I always assumed that if NA == NA [1] NA then an attempt to compare NA to elements in a vector would also return NA, but not so. NA %in% c(1,NA,3) [1] TRUE Learned something new today, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] choosing a random sample by precentage
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Xebar Saram Sent: Thursday, July 22, 2010 3:50 PM To: r-help@r-project.org Subject: [R] choosing a random sample by precentage hi all i have found the follwoing way to choose a random sample by sample size (200): ten_per_T2000 - F_T2000_All[sample(nrow(F_T2000_All), 200), ] but i wondered if there is a way to choose a sample size by precentage (10% etc..) thx ethan Maybe something like: ten_per_T2000 - F_T2000_All[sample(nrow(F_T2000_All), 0.1*nrow(F_T2000_All)), ] Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 define a function in R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of jd6688 Sent: Tuesday, July 06, 2010 3:49 PM To: r-help@r-project.org Subject: [R] how to define a function in R 1. how to write a R script? 2.How to write a SAS like macro/generic process to process multiple files by using the same funstion in R? Thanks in advance Don't thank me too soon. :-) Your question is equivalent to me going to SAS-L and asking someone to teach me SAS macro language. You need to provide more information about what your task actually is. Where are these file names that you want to process coming from? What do you want to do with them? The basic approach would be to put the file names in a list and then pass the list items one at a time to your function. But how to do that really depends on what you are trying to do. You might also read the posting guide listed at the bottom of every posting. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] gsub issue in R 2.11.1, but not present in 2.9.2
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Bert Gunter Sent: Tuesday, June 29, 2010 11:08 AM To: 'Jason Rupert'; 'Duncan Murdoch' Cc: r-help@r-project.org Subject: Re: [R] gsub issue in R 2.11.1, but not present in 2.9.2 Jason: I think it's actually even a bit worse than what Duncan said, which was: --- You need to double the backslashes to enter them in an R string. So gsub(N\\A, NA, original, fixed=TRUE) should work if original contains a single backslash, and gsub(NA, NA, original, fixed=TRUE) should work if it contains a double one. Two things add to the confusion here: First, a single backslash will be displayed doubled by print(). .. -- Well, let's see: (On R version 2.11.1, 2010-5-31 for Windows) astring - n\a print(astring) [1] n\a So Duncan's last sentence appears to be incorrect. The \ is not displayed doubled. However ... But Duncan's statement is correct. In your example above, there is no backslash character in the variable astring. It contains the letter 'n' and the control character '\a', which is a single character (the backslash is printed by print() to indicated the control character). If there was actually a backslash character in the string, print() would have doubled. bstring - N\A Error: '\A' is an unrecognized escape in character string starting N\A What's going on? Well, the \a in astring is a _single escape sequence (for a beep/bell sound, on Windows anyway: cat(\a) should make a sound). So the \ in \a is printed as correctly undoubled. However, since the \A in bstring does _not_ correspond to any escape sequence, the expression \A cannot be parsed and an error is thrown. But: bstring - N\\A print(bstring) [1] N\\A ## is fine ## ... Noting that nchar(\\A) [1] 2 So whether a \ needs to be doubled or not depends on whether the parser can interpret it as part of a legitimate escape sequence, whence gsub(\a,,\a) ## works but gsub(\A,,\A) ## does not. Whether \ needs to be doubled depends on what you want the string value to be. If you want the single control character, '\a', then you don't want to double it. If you want the string to contain 2 characters '\' and 'a', then you must enter '\\a'. To avoid such confusion, I think Duncan's advice to double backslashes should be heeded as much as possible. Unfortunately, I don't think it's always possible: In this case, if you actually want a newline character, then you don't want to use a double backslash. newlineString - first line\nsecond line\n print(newlineString) [1] first line\nsecond line\n cat(newlineString) first line second line Cheers, Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Is there a non-parametric repeated-measures Anova in R ?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Tal Galili Sent: Wednesday, June 16, 2010 10:44 AM To: Jeremy Miles Cc: r-help@r-project.org Subject: Re: [R] Is there a non-parametric repeated-measures Anova in R ? Hello Jeremy, Thank you for replying. I came across friedman test (I even wrote and published R code to easily perform a post-hoc analysis of friedman testhttp://www.r-statistics.com/2010/02/post-hoc-analysis-for- friedmans-test-r-code/ ). But what I am after is *multi-way* repeated-measures anova. Thank you for your reply which allowed me to clarify my intentions. Best, Tal Tal, Maybe this paper will give you some ideas. http://www.apsnet.org/phyto/janpdf/1113-01O.pdf Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 Matching Exact Values
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Brigid Mooney Sent: Wednesday, June 09, 2010 1:49 PM To: r-help@r-project.org Subject: [R] Problem Matching Exact Values Sorry for the basic question - bur I ran into something I haven't noticed before and would appreciate a little more perspective on my problem. I am using R to determine if various thresholds are hit (or surpassed) in a data set. If a threshold is surpassed, I have had no problems identifying it. However, when the threshold is matched *exactly*, not all cases are being identified. Please consider the following example, with base value of x = 59000 and threshold of 10% - so the target to hit is 59000*1.1 = 64900. x - 59000 thresh - 0.10 target - x*(1+thresh) target [1] 64900 target == 64900 [1] FALSE target-64900 [1] 7.275958e-12 Why is there this (very) small difference in the value of target and the numeric 64900? Is this using a floating point system or something else that I'm not understanding? Yes, it is a finite precision problem, due to converting decimal to binary floating-point. See FAQ 7.31 Is using round() the best work-around in cases such as these - or is there a better (perhaps more accurate) way to classify data in cases such as this - avoiding whatever floating points are taking place in the background in the first place?. Hope this is helpuf, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] rounding up to nearest integer
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Mohan L Sent: Monday, May 24, 2010 6:26 PM To: r-help@r-project.org Subject: [R] rounding up to nearest integer Dear All, I have a data frame data and the below is the str of data : $ Feb : int 1 1195 0 11 28 152 24 2 1 1470 ... $ Mar : int 0 1212 0 17 27 184 15 1 1 1311 ... $ Apr : int 2 1244 1 15 23 135 11 0 1 991 ... $ May : int 2 1158 2 10 23 111 16 1 1 1237 ... $ Jun : int 0 845 1 9 16 86 16 2 1 1129 ... $ Jul : int 0 832 0 7 16 68 9 1 0 994 ... $ Aug : int 0 1107 1 4 25 144 7 0 3 1260 ... $ Sep : int 2 1278 1 8 53 212 14 0 3 1375 ... $ Oct : int 3 1329 0 8 39 201 13 0 0 1340 ... $ Nov : int 1 1179 0 5 7 135 2 0 0 1153 ... $ Dec : int 0 1271 0 7 34 168 5 1 2 1792 ... $ Jan.10: int 0 1405 1 10 55 245 26 2 4 2806 ... $ Feb.10: int 0 1330 1 9 29 360 27 3 6 3492 ... $ Mar.10: int 0 1727 0 8 7 341 8 2 4 4578 ... $ Apr.10: int 0 1530 1 8 12 144 7 2 2 5453 ... I am doing some this like this : x - (data[,-(1:2)] - data[,2]) * prop.table(data[,2]) + data[,2] x Feb Mar Apr May Jun Jul 1 1.000.5971.4031.4030.597 0.597 2 1292.610851 1293.5003225 1295.1746211 1290.6749436 1274.2982103 1273.6180264 Now the str of x is : str(x) 'data.frame':32 obs. of 15 variables: $ Feb : num 1 1293 0 5 18 ... $ Mar : num 1 1294 0 5 18 ... $ Apr : num 1 1295 0 5 18 ... $ May : num 1 1291 0 5 18 ... $ Jun : num 1 1274 0 5 18 ... $ Jul : num 1 1274 0 5 18 ... $ Aug : num 1 1288 0 5 18 ... $ Sep : num 1 1297 0 5 18 ... $ Oct : num 1 1300 0 5 18 ... $ Nov : num 1 1292 0 5 18 ... $ Dec : num 1 1297 0 5 18 ... $ Jan.10: num 1 1303.6 0 5 18 ... $ Feb.10: num 1 1300 0 5 18 ... $ Mar.10: num 1 1320 0 5 18 ... $ Apr.10: num 1 1310 0 5 18 ... I need to round up the data frame some thing like this : Feb Mar Apr May Jun Jul 1 1 11 1 1 1 2 1293 1294 1295 1291 1274 1274 there may be a way to round up the nearest integer. any help will be greatly appropriated. Thanks Rg Mohan L If you truly want to round up, look at ?ceiling Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] intersect() without discarding duplicates?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jonathan Sent: Thursday, May 20, 2010 3:25 PM To: David Winsemius Cc: r-help Subject: Re: [R] intersect() without discarding duplicates? Thanks, but that doesn't quite work, since I'd want the result of b[b %in% a] to be symmetric with a[a%in%b] (so if there are two 2's in EACH vector, I'll get two 2's in the result, but if there are two 2's in only one vector, but one two in the other, the result will show only one 2. Consider: a - c(2,4,3) b-c(6,6,5,2,2,8,4) b[b %in% a] [1] 2 2 4 a[a%in%b] [1] 2 4 The second answer is correct, but I can't predict which variable to put in which position in the statement, so I'd need them both to be correct. Best, Jonathan I think you have misread the intersect documentation. Given your examples above intersect is what you in fact want. a - c(2,4,3) b-c(6,6,5,2,2,8,4) intersect(a,b) [1] 2 4 Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] sem error no variance or error-variance parameter
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Jan Schubert Sent: Tuesday, May 18, 2010 12:51 PM To: r-help@r-project.org Subject: [R] sem error no variance or error-variance parameter Hi, I am sorry to post the message again but I really need some advise on that. I am using the R version 2.11.0 and the version of sem package: sem_0.9-20 under Windows XP. I read the questions: http://r.789695.n4.nabble.com/computationally-singular-and-lack-of- variance-parameters-in-SEM-td891081.html#a891082 and http://r.789695.n4.nabble.com/computationally-singular-and-lack-of- variance-parameters-in-SEM-td891081.html#a891081 but it does not seem to be my problem. I try to replicate the sem model (see the attacheted image) but i got stuck with the problem while computing the estimates of the model: The error message: Error in nlm(if (analytic.gradient) objective.2 else objective.1, start, : probable coding error in analytic gradient In addition: Warning message: In sem.default(ram = ram, S = S, N = N, param.names = pars, var.names = vars, : The following variables have no variance or error-variance parameter (double-headed arrow): Fugural1 The model is almost surely misspecified; check also for missing covariances. Here is my script: cov.matrix - matrix(c(56.21,0,0,0,0,0,0,0,0,31.55,75.55,0,0,0,0,0,0,0,23.27,28.30,44 .45,0,0,0,0,0,0,24.48,32.24,22.56,84.64,0,0,0,0,0,22.51,29.54,20.61,57. 61,78.93,0,0,0,0,22.65,27.56,15.33,53.57,49.27,73.76,0,0,0,33.24,46.49, 31.44,67.81,54.76,54.58,141.77,0,0,32.56,40.37,25.58,55.82,55.33,47.74, 98.62,117.33,0,30.32,40.44,27.69,54.78,53.44,59.52,96.95,84.87,106.35), nrow=9,ncol=9,byrow=FALSE) rownames(cov.matrix) - colnames(cov.matrix) - c(IND1,IND2,IND3,FR11,FR12,FR13,FR21,FR22,FR23) # options(nlm=(check.analyticals = TRUE)); I tried to set the nlm on different option, but did not work either m1 - specify.model() Induction - IND1, NA, 1 Induction - IND2, y2, NA Induction - IND3, y3, NA Fugural1 - FR11, NA, 1 Figural1 - FR12, y5, NA Figural1 - FR13, y6, NA Figural2 - FR21, NA, 1 Figural2 - FR22, y8, NA Figural2 - FR23, y9, NA Induction - Figural1, x1, NA Figural1 - Figural2,x2, NA Induction - Figural2, x3, NA IND1 - IND1, e1, NA IND2 - IND2, e2, NA IND3 - IND3, e3, NA FR11 - FR11, e4, NA FR12 - FR12, e5, NA FR13 - FR13, e6, NA FR21 - FR21,e7, NA FR22 - FR22, e8, NA FR23 - FR23, e9, NA Figural1 - Figural1, e10, NA Figural2 - Figural2, e11, NA Induction - Induction, NA, 1 sem1 - sem(m1,cov.matrix,N=220,debug=T) # I added the Induction - Induction, NA, 1 fixed parametr after reading the help from John Fox, that every variable should have an error variance Can anybody please advise me what I am doing wrong? Many thanks! Jan Schubert Institute of Social Science Charles University, Prague -- Jan, I didn't go through your model in detail, but if you look carefully at the error message, you appear to have misspelled Figural1 as Fugural1. When I corrected that problem, your example ran without error. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Read data from .csv file as a matrix
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of vincent.deluard Sent: Wednesday, May 05, 2010 12:34 PM To: r-help@r-project.org Subject: [R] Read data from .csv file as a matrix Hi R-users, I have a csv file that contains weather observation (rows) by days (in columns). I open using: temp = read.csv(Weather.csv, sep=,) and read: X X1.Jan X2.Jan X3.Jan X4.Jan 1 Min 2 3 4 1 2 Max 6 10 8 6 3 Forecast Min 3 1 1 3 4 Forecast Max 8 7 4 9 If I type mean(temp[2,2:3]) I get X1.Jan X2.Jan 6 10 The same command on y = matrix(1:21, ncol=7) mean(y[2,2:3]) [1] 6.5 Works because the data is in a matrix. I believe R stores the data from the csv file as a data.frame with these annoying headers. So how do I convert the data from my csv file into a matrix? I tried as.matrix but it did not help. Many many thanks! I'm only guessing because you haven't given us much to go on, but maybe something like mean(unlist(temp[2,2:3])) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Dynamic clustering?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- project.org] On Behalf Of Erik Iverson Sent: Wednesday, May 05, 2010 2:33 PM To: Ralf B Cc: r-help@r-project.org Subject: Re: [R] Dynamic clustering? Hello, Ralf B wrote: Are there R packages that allow for dynamic clustering, i.e. where the number of clusters are not predefined? I have a list of numbers that falls in either 2 or just 1 cluster. Here an example of one that should be clustered into two clusters: two - c(1,2,3,2,3,1,2,3,400,300,400) and here one that only contains one cluster and would therefore not need to be clustered at all. one - c(400,402,405, 401,410,415, 407,412) Given a sufficiently large amount of data, a statistical test or an effect size should be able to determined if a data set makes sense to be divided i.e. if there are two groups that differ well enough. I am not familiar with the underlying techniques in kmeans, but I know that it blindly divides both data sets based on the predefined number of clusters. Are there any more sophisticated methods that allow me to determine the number of clusters in a data set based on statistical tests or effect sizes ? snip Ralf, There is no procedure in R or any other stat package that can make these kinds of decisions without a whole lot more specification of the problem. You give two examples above. What would you want done with c(380, 400, 402, 405, 401, 410, 415, 407, 412), or c(350, 400, 402, 405, 401, 410, 415, 407, 412), or c(300, 400, 402, 405, 401, 410, 415, 407, 412), or c(100, 400, 402, 405, 401, 410, 415, 407, 412), or ... i.e. what difference counts as big enough or variable enough or ...? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Read SAS data
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nicola Sturaro Sommacal Sent: Thursday, March 25, 2010 9:16 AM To: r-help@r-project.org Subject: [R] Read SAS data Hi! I need to import in R some SAS dataset (sas7bdat). I found two functions to do it: read.ssd from the package foreign and sas.get from Hmisc. df = read.ssd(libname = path2data, sectionnames = sasSmallDataset, tmpXport = path2data, tmpProgLoc = path2data, sascmd = path2sas) sas.get(libraryName = path2data, member = sasSmallDataset, formats = FALSE, sasprog = path2sas, keep.log = TRUE) where path2data is the directory on which is contained the file sas, sasSmallDataset.sas7bdat are the data and path2sas is the path to SAS (C:/Programmi/SAS/SAS System/9.0/sas.exe). I obtain the following messages: from read.ssd: SAS failed. SAS program at Z:/projects/QUANTIDE/import2R/.sas The log file will be import2R.log in the current directory Warning messages: 1: In file.symlink(oldPath, linkPath) : symlinks are not supported on this platform 2: In read.ssd(libname = path2data, sectionnames = sasSmallDataset, : SAS return code was 2 from sas.get: Error in if (status != 0) { : argument is of length zero I have SAS 9.0 and R 2.10.1 running on Windows XP Pro. Can you help me to found a solution or can you provide an alternative way to import SAS data directly from R? Thank you very much. -- Nicola Sturaro Sommacal Quantide srl http://www.quantide.com Here is one work-around for sas.get on MS Windows platforms. http://finzi.psych.upenn.edu/Rhelp10/2008-December/182573.html Here is another thread that you might find useful. http://tolstoy.newcastle.edu.au/R/e9/help/10/02/6248.html Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Convert number to Date
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Joshua Wiley Sent: Thursday, March 25, 2010 1:48 PM To: anna Cc: r-help@r-project.org Subject: Re: [R] Convert number to Date Dear Anna, Rolf's explanation not withstanding, it has to do with differences in how R and Excel treat dates. If you use as.Date(40182, origin=1899-12-30) you will get the same date as Excel. You can look at: http://office.microsoft.com/training/training.aspx?AssetID=RC102786151033CTT= 6Origin=RP102786121033 For an official guide on how Excel dates are calculated. Apparently, Excel's calendar starts on 1 January 1900. Why one has to use an origin of 30 December 1899 in R...well, I suspect that gets back to Rolf's explanation. HTH, Josh snip The reason one must use 1899-12-30, as the origin, is 1. Excel treats 1900-01-01 as day 1, but as.Date() teats the origin as day 0. 2. According to Wikipedia, Excel copied the Lotus 1-2-3 error of making 1900 a leap year (an extra day) That accounts for the two day difference. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Convert number to Date
Rolf, I tried the same thing at first, and got the same error. So I suspect Anna didn't really use that code either. :-) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Rolf Turner Sent: Thursday, March 25, 2010 3:09 PM To: Joshua Wiley Cc: r-help@r-project.org Subject: Re: [R] Convert number to Date Kind of off the thread a bit, but when I do: as.Date(40182) I ***do not*** get 2080-01-06. Instead I get an error: Error in as.Date.numeric(40182) : 'origin' must be supplied Am I the only user who gets picked on in this way, or does it happen to others as well? The help on as.Date() clearly specifies that origin must be supplied. So how come Anna got the result that she did? sessionInfo() R version 2.10.1 (2009-12-14) i386-apple-darwin8.11.1 locale: [1] en_NZ.UTF-8/en_NZ.UTF-8/C/C/en_NZ.UTF-8/en_NZ.UTF-8 attached base packages: [1] datasets utils stats graphics grDevices methods base other attached packages: [1] misc_0.0-12fortunes_1.3-7 MASS_7.3-4 cheers, Rolf Turner On 26/03/2010, at 9:47 AM, Joshua Wiley wrote: Dear Anna, Rolf's explanation not withstanding, it has to do with differences in how R and Excel treat dates. If you use as.Date(40182, origin=1899-12-30) you will get the same date as Excel. You can look at: http://office.microsoft.com/training/training.aspx?AssetID=RC102786151033CTT= 6Origin=RP102786121033 For an official guide on how Excel dates are calculated. Apparently, Excel's calendar starts on 1 January 1900. Why one has to use an origin of 30 December 1899 in R...well, I suspect that gets back to Rolf's explanation. HTH, Josh On Thu, Mar 25, 2010 at 1:33 PM, anna lippelann...@hotmail.com wrote: Hello, I have a date value in excel: 1/4/2010 which in number format gives me 40182. When I read this with read.xls from R I get same 40182 so what I do is that I use the as.Date() function but here is what the as.Date() function returns me: as.Date(40182) [1] 2080-01-06 Why don't I get the same thing as in excel? Thanks! ### ### Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.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.
Re: [R] counting the number of ones in a vector
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of sjaffe Sent: Thursday, March 04, 2010 10:59 AM To: r-help@r-project.org Subject: Re: [R] counting the number of ones in a vector I got tired of writing length(which()) so I define a useful function which I source in my .Rprofile: count - function( x ) length(which(x)) Then: count( x == 1 ) How about sum(x==1) ? No need to write a new function, and it is even 2 characters less to type. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Reading sas7bdat files directly
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Roger DeAngelis(xlr82sas) Sent: Monday, March 01, 2010 4:38 PM To: r-help@r-project.org Subject: Re: [R] Reading sas7bdat files directly Hi All, The hack below might help R users get going with Chris's DSREAD. I have not had a chance to look at Monday's version of DSREAD, can't wait. Note Duncan Murdoch was most gracious to supply me with a R function to translate floats in 16 char hex to R floats. Your utility solves the 200 byte, 8 char name and potential precision errors with other methods of transfering SAS datasets to perl and R. Thanks. Importing SAS datasets(sas7bdat) into R (32 bit windows 2000, 32 bit SAS 9.2 and 32 bit R version 2.9.0 (2009-04-17) Here is what I want to accomplish, the double floats below show data from SAS to R. They are exactly the same in R and SAS memory, bit for bit. R Internal SAS Internal 16 Byte Float 16 byte Float 3FFB 3FFB 4002AAAB 4002AAAB 400D 400D 3FF6 3FF6 3FFD 3FFD 4001999A 4001999A 4004CCCD 4004CCCD 3FF4924924924925 3FF4924924924925 3FF9249249249249 3FF9249249249249 3FFDB6DB6DB6DB6E 3FFDB6DB6DB6DB6E 4001249249249249 4001249249249249 3FF2E8BA2E8BA2E9 3FF2E8BA2E8BA2E9 3FF5D1745D1745D1 3FF5D1745D1745D1 3FF8BA2E8BA2E8BA 3FF8BA2E8BA2E8BA 3FFBA2E8BA2E8BA3 3FFBA2E8BA2E8BA3 3FF2762762762762 3FF2762762762762 3FF4EC4EC4EC4EC5 3FF4EC4EC4EC4EC5 3FF7627627627627 3FF7627627627627 3FF9D89D89D89D8A 3FF9D89D89D89D8A 1.7976931348623E 1.7976931348623E 0010 0010 I don't believe this high accuracy transfer is possible with any other method except ODBC, but SAS ODBC is unsatisfactory for me. If you use CSV with the maximum assured decimal precision(15 significant digits?). The CSV decimal numbers will only approximate the double floats. I consider the Csv to be corrupt if the relative of absolute difference using the decimal Csv numbers and the memory floats is greater than 10^-12. There are two sources of error first the SAS floats are decimally rounded and converted to decimal then the rounded decimal approximations are converted into R floats. Status of R InternalCSV Csv 16 Byte Float Csv corrupt 3FFB 1.6710^-12 different Csv corrupt 4002AAAB 2.33 Csv corrupt 400D 3.67 Csv OK 3FF6 1.4 Csv OK 3FFD 1.8 Csv OK 4001999A 2.2 Csv OK 4004CCCD 2.6 Csv corrupt 3FF4924924924925 1.28571428571429 Csv corrupt 3FF9249249249249 1.57142857142857 Csv corrupt 3FFDB6DB6DB6DB6E 1.85714285714286 Csv corrupt 4001249249249249 2.14285714285714 Csv corrupt 3FF2E8BA2E8BA2E9 1.18181818181818 Csv corrupt 3FF5D1745D1745D1 1.36363636363636 Csv corrupt 3FF8BA2E8BA2E8BA 1.54545454545455 Csv corrupt 3FFBA2E8BA2E8BA3 1.72727272727273 Csv corrupt 3FF2762762762762 1.15384615384615 Csv corrupt 3FF4EC4EC4EC4EC5 1.30769230769231 Csv corrupt 3FF7627627627627 1.46153846153846 Csv corrupt 3FF9D89D89D89D8A 1.61538461538462 Csv corrupt 1.7976931348623E 1.7976931348623E+308 Csv corrupt 0010 2.2250738585072E-308 Bacground 1. Provide absolutely loss less transfer of character(max 32756 bytes per character variable) and numeric data from SAS to R Since SAS has only two datatypes so this code should be exhaustive. 2. This code is useful because: a. The SAS ODBC driver requires the user to not only have SAS but the user must bring up a SAS session and the session has to be closed manually. (SAS issue not a foreign issue) b. The foreign package also requires interaction with SAS. (SAS issue) c. SASxport only supports 8 character SAS names and a max of 200 byte character values. (This is a SAS issue not a SASxport issue) d. SASxport creates floating point doubles that have an 8 bit exponent and 56 bit mantissa while IEEE is 11 bit exponent and 53 bit mantissa (sometimes defined slightly differently depending of where you consider the sign bits). This results is the loss of some very small and very large numbers. ( SAS issue not a SASxport issue) 3. How this code overcomes the issues above for import only. You need the dsread exec in the previous mesage. Also the input SAS dataset must have 16 byte character representations for the floats. I am working with the developer to see what we can do about this.. He will make it an option on the invocation to do the hex conversion for numerics. Here is the R code run inside a SAS datastep. Actually
Re: [R] Plotting 15 million points
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Abhishek Pratap Sent: Thursday, February 25, 2010 3:12 PM To: r-help@r-project.org Subject: [R] Plotting 15 million points Hi All I have a vector of about 15 million numbers which I would like to plot. The goal is the see the distribution. I tired the usual steps. 1. Histogram : never gets complete my window freezes w/out log base 10 2. Density : I first calculated the kernel density and then plotted it which worked. It would be nice to superimpose histogram with density but as of now I am not able to get this data as a histogram. I tried ggplot2 which also hangs. Any efficient methods to play with 10 million numbers in a vector. Thanks, -Abhi You need to show us what you did. Generating 15 million random normals and plotting a histogram worked just fine on my desktop in a matter of ~6 seconds. x - rnorm(15e6) hist(x) Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Use of R in clinical trials
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Dalgaard Sent: Thursday, February 18, 2010 12:44 PM To: Douglas Bates Cc: r-help@r-project.org; Bert Gunter Subject: Re: [R] Use of R in clinical trials (Corrections/additional information welcome!) My recollection is that the BMD programs (which, in a later version, became BMDP) predated SAS and were specifically for BioMeDical analysis. How could I forget those! Yes, my old (as in 1980-1985) boss at the University hospital even had the manual in the office. It wasn't a statistical system though, more a suite of single-purpose computer programs with a rigid control-card specification format. BTW, they were apparently put in the public domain by UCLA, but I wonder where they went? I believe BMDP was bought by SPSS around 1996. SPSS also purchased Systat in that same time period I believe. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Odp: Creating Dummy Variables in R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of whitaker m. (mw1006) Sent: Wednesday, December 16, 2009 2:14 PM To: Nikhil Kaza; Petr PIKAL Cc: r-help@r-project.org Subject: Re: [R] Odp: Creating Dummy Variables in R I have a much larger dataset than in my original email (attached - price dependent upon weight, Clarity (different levels IF-SI2), colour(levels D-L) and Cut (ideal-fair), and tried the regression command: diamond.lm- lm(price~weight+IF+VVS1+VVS2+VS1+VS2+SI1+SI2+I1+I2+D+E+F+G+H+I+J+K +L+ideal+excellent+very.good+good+fair, data=Diamonds2.txt) Error in eval(predvars, data, env) : invalid 'envir' argument Which lead to the error message below the command. I have tried searching for this, and assumed this was down to having categrocial variables within the data, is this a correct assumption or am i doing something else wrong? Apologies if this is a bit of a basic question! Thanks again, Matthew You need to read your data from Diamonds2.txt into a dataframe first before running the lm() function. What does your file Diamonds2.txt look like? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] read dataset in R language.
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nancy Adam Sent: Tuesday, December 15, 2009 1:24 PM To: r-help@r-project.org Subject: Re: [R] read dataset in R language. Hi all,Thanks for your reply. Sorry I did not send sufficient information about my problem…I attach the two datasets that I’m trying to read and these are my attempts to read them:1)#train - read.table(trainingset.txt, header=TRUE, sep=; ,fill=TRUE) #test - read.table(testset.txt, header=TRUE, sep=; , fill=TRUE)its error message is: “ undefined columns selected”2)train - scan(trainingset.txt, sep=; ,fill=TRUE) test - scan(testset.txt, sep=; , fill=TRUE) its error message is: “ 'names' attribute [172] must be the same length as the vector [152]” many thanks, Nancy Nancy, I took a quick look at your training set data file and I see a couple of problems. 1. You have some name fields that aren't legal names in the header. 2. It appears that you have more variable names in your header than you have data fields on each line. These issues will need to be cleaned up before you can read the file. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Confidence intervals - a statistical question, nothing to do with R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Moshe Olshansky Sent: Wednesday, November 18, 2009 3:21 PM To: R-help@r-project.org Subject: [R] Confidence intervals - a statistical question, nothing to do with R Dear list, I have r towns, T1,...,Tr where town i has population Ni. For each town I randomly sampled Mi individuals and found that Ki of them have a certain property. So Pi = Ki/Mi is an unbiased estimate of the proportion of people in town i having that property and the weighted average of Pi is an unbiased estimate of the proportion of the entire population (all r towns) having this property. I can compute confidence intervals for the proportion of people having that property for each city (in my case Mi Ni and so binomial distribution is a good approximation to Ki). My question is: how can I compute confidence interval for the proportion of people in the entire population (r towns) having that property? Either analytical or numerical (simulation?) method will be all right. Thank you in advance, Moshe. You might want to look at the survey package for getting appropriate variance estimates. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] :Problem with Looping
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bruno Giovannetti Sent: Tuesday, November 17, 2009 3:18 PM To: r-help@r-project.org Subject: [R] :Problem with Looping Hello, Sometimes the looping (using for) seems to skip some iterations. An example: arg - matrix(NA,length(seq(.30,.5,.01)),1) for (i in seq(.30,.5,.01)) { arg[i*100-29] - i } arg What is the problem with this coding, please? Thank you so much, -- Bruno Cara Giovannetti, PhD Candidate Economics Department Columbia University Personal Webpage: www.columbia.edu/~bcg2108 Don't use floating point operations in your indexing. You may also want to change how you generate your sequence. This is a floating point representation problem. See FAQ 7.31. Try something like this arg - matrix(NA,length(seq(30,50,1)),1) for (i in seq(30,50,1)) {arg[i-29] - i/100 } Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] strsplit() and Windows file paths
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Robert Baer Sent: Thursday, October 29, 2009 12:40 PM To: r-help@r-project.org Subject: [R] strsplit() and Windows file paths There are two ways to express file paths with the Windows environment: a=file.choose() a [1] C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused 20k F5 0ng Ki8751 t20.txt and b= paste(getwd(),/,dir()[1],sep=) b [1] C:/Documents and Settings/rbaer/Desktop/_VNT_Test/coordFocused 20k F5 0ng Ki8751 t20.txt I have 2 questions: 1. Is it possible to get file.choose() to use the forward slash rather than the escaped back slash. It would be nice if it were consistent with dir() and getwd() Sorry, don't know. 2. If one has a path string like the escaped backslash pattern shown in 1 above, how does one do a strsplit() on these escaped backslashs? Use ? s - C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused 20k F5 0ng Ki8751 t20.txt strsplit(s,) [[1]] [1] C: [2] Documents and Settings [3] rbaer [4] Desktop [5] _VNT_Test [6] coordFocused 20k F5 0ng Ki8751 t20.txt Thanks, Rob - Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] strsplit() and Windows file paths
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nordlund, Dan (DSHS/RDA) Sent: Thursday, October 29, 2009 12:57 PM To: r-help@r-project.org Subject: Re: [R] strsplit() and Windows file paths -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Robert Baer Sent: Thursday, October 29, 2009 12:40 PM To: r-help@r-project.org Subject: [R] strsplit() and Windows file paths There are two ways to express file paths with the Windows environment: a=file.choose() a [1] C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused 20k F5 0ng Ki8751 t20.txt and b= paste(getwd(),/,dir()[1],sep=) b [1] C:/Documents and Settings/rbaer/Desktop/_VNT_Test/coordFocused 20k F5 0ng Ki8751 t20.txt I have 2 questions: 1. Is it possible to get file.choose() to use the forward slash rather than the escaped back slash. It would be nice if it were consistent with dir() and getwd() Sorry, don't know. 2. If one has a path string like the escaped backslash pattern shown in 1 above, how does one do a strsplit() on these escaped backslashs? Use ? s - C:\\Documents and Settings\\rbaer\\Desktop\\_VNT_Test\\coordFocused 20k F5 0ng Ki8751 t20.txt strsplit(s,) [[1]] [1] C: [2] Documents and Settings [3] rbaer [4] Desktop [5] _VNT_Test [6] coordFocused 20k F5 0ng Ki8751 t20.txt Thanks, Rob - It was pointed out to me off-list that it would be easier and faster to use strsplit(s,\\,fixed=TRUE) I will now go back and read ?strsplit more carefully :-). Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Problems importing Unix SAS .ssd04 file to R (Win)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of johannes rara Sent: Tuesday, October 20, 2009 12:26 AM To: r-help@r-project.org Subject: [R] Problems importing Unix SAS .ssd04 file to R (Win) Hello, I'm trying to import a SAS file made using SAS on Unix. Currently I'm using SAS on Windows and I'm trying to import that .ssd04 file to R. The file name of the file is testfile.ssd04 and it is located in 'M:\sasuser'. I'm using Windows XP and R 2.91. Basically what I'm doing is r code ## library(foreign) sashome - C:/Program Files/SAS Institute/SAS/V8 folder_for_datafiles - M:/sasuser read.ssd(folder_for_datafiles, testfile, sascmd=file.path(sashome, sas.exe)) SAS failed. SAS program at C:\DOCUME~1\jrara\LOCALS~1\Temp\RtmpAAxO3X\file41bb5af1.sas The log file will be file41bb5af1.log in the current directory NULL Warning message: In read.ssd(folder_for_datafiles, testfile, sascmd = file.path(sashome, : SAS return code was 2 ## This temporary SAS file 'file41bb5af1.sas' looks like this sas code # option validvarname = v6;libname src2rd 'M:/sasuser'; libname rd xport 'C:\DOCUME~1\jrara\LOCALS~1\Temp\RtmpAAxO3X\file6df11649'; proc copy in=src2rd out=rd; select testfile ; ## Any ideas what I'm doing wrong? sessionInfo() R version 2.9.1 (2009-06-26) i386-pc-mingw32 locale: LC_COLLATE=Finnish_Finland.1252;LC_CTYPE=Finnish_Finland.1252;LC_MON ETARY=Finnish_Finland.1252;LC_NUMERIC=C;LC_TIME=Finnish_Finland.1252 attached base packages: [1] graphics grDevices utils datasets grid stats methods base other attached packages: [1] foreign_0.8-38 gregmisc_2.1.1 gplots_2.7.1 caTools_1.9 bitops_1.0-4.1 gtools_2.6.1 gmodels_2.15.0 gdata_2.6.1 loaded via a namespace (and not attached): [1] MASS_7.2-49 C can you read that dataset just using your Windows SAS v8? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] cdf
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of maram salem Sent: Tuesday, October 13, 2009 2:13 PM To: r-help Subject: [R] cdf Dear all, I have the cdf of the following power fuction distribution: F(y)=(y/350)^a ,0y350, where a is some parameter with range a0. I want to use it as the argument of the discretize function of the actuar package. So I think I need to define this function to R so that if I entered a=1, I get the following F(y)=(y/350) and if I entered a=4.5, I get the following F(y) =(y/350)^4.5 ... and so on I've tried a-vector(mode=numeric,length=1) powercdf-function(a,y) (y/350)^a But when I typed: powercdf(10,y) instead of getting : (y/350)^10 (which is what I want) I got : object y not found ?? I want y to remain as it is, a continous variable, not for example seq(0,350). Thank you in advance. Maram You say I want y to remain as it is, where is y defined outside of your function? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Rounding error in seq(...)
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Douglas Bates Sent: Wednesday, September 30, 2009 3:06 PM To: Peter Dalgaard Cc: r help; Duncan Murdoch Subject: Re: [R] Rounding error in seq(...) On Wed, Sep 30, 2009 at 2:32 PM, Peter Dalgaardp.dalga...@biostat.ku.dk wrote: Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? why is x - 0.1 + 0.1 +0.1 not equal to y - 0.3 Remember that this is in BINARY arithmetic. It's really not any stranger than the fact that 1/3 + 1/3 != 2/3 in finite accuracy decimal arithmetic (0.3 + 0.3 = 0.6 != 0.7). In an earlier thread on this theme I believe that someone quoted Brian Kernighan as saying 10 times 0.1 is hardly ever 1 but I haven't been able to track down the quote. Can anyone point us to such a quote? It summarizes the situation succinctly, The first page of this document references: http://www.stats.ox.ac.uk/~ruth/RCourse/Numerics.pdf ‘The Elements of Programming Style’ by Kernighan and Plauger Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Rounding error in seq(...)
-Original Message- From: Peter Dalgaard [mailto:p.dalga...@biostat.ku.dk] Sent: Wednesday, September 30, 2009 3:58 PM To: Nordlund, Dan (DSHS/RDA) Cc: Douglas Bates; r help Subject: Re: [R] Rounding error in seq(...) snip The first page of this document references: http://www.stats.ox.ac.uk/~ruth/RCourse/Numerics.pdf ‘The Elements of Programming Style’ by Kernighan and Plauger Actually, it cites the R FAQ, Q. 7.31 in extenso... Right you are Peter. I just Googled the phrase and looked at the immediate context of the phrase, and not much else of the document (since I was looking for a Kernighan reference). Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Help on percentage of random numbers for different classes
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of KABELI MEFANE Sent: Wednesday, September 09, 2009 4:06 PM To: R-help@r-project.org Subject: Re: [R] Help on percentage of random numbers for different classes R-list I am sorry for asking this stupid question, but i have been running in circles. I want to randomly generate a scaling point of between 1 and 10, for say hundred entries, where the first 10% percent is has rates between 2 and 7, the next 15% 3 and 7, 20% between 3 and 9, 20% between 3 and 10, 35% between 5 and 10. The problem is that i can only generate the usual 100 using runif function y-c(ceiling(10*runif(100))) y [1] 10 8 5 2 4 1 6 7 1 6 8 8 8 9 7 7 8 8 2 7 3 10 1 7 1 [26] 10 4 8 8 8 9 3 7 8 4 6 7 2 3 1 9 8 2 6 7 4 8 8 9 7 [51] 6 5 4 1 8 7 9 8 10 5 3 7 5 5 4 4 7 4 10 4 9 1 5 10 10 [76] 5 5 10 7 3 4 4 9 10 6 2 6 6 6 3 8 2 2 4 4 10 6 9 4 3 I just want to try to avoid small numbers as much as possible. I am open to suggestions, please please please. Kabeli If I understand you correctly, this might do what you want. n is a vector with the number samples you want in each range, x is then minimum for each range and y is the maximum. The function, s, samples from a given range, a specified number of times. mapply applies the function using the first, second, ... elements in turn returning a list with the samples. n - c(10,15,20,20,35) x - c(2,3,3,3,5) y - c(7,7,9,10,10) s - function(mn, mx, n) {sample(mn:mx, n, replace=TRUE)} unlist(mapply(s, x, y, n)) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Party plots
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of AnnieE Sent: Thursday, September 03, 2009 12:57 PM To: r-help@r-project.org Subject: Re: [R] Party plots Achim Zeileis wrote: You can easily plot into a large PDF, e.g., something like this pdf(file = foo.pdf, height = 15, width = 20) plot(foo) dev.off() and then view the PDF in an external viewer, zooming into parts of a tree etc. Depending on the size of the tree in foo, you might have to adjust height/width accordingly. Thanks very much. That sounds like just what I'm looking for and have been unable to ferret out in my search through manuals and forums. I'm still a bit stuck though, because of my unfamiliarity with pulling stuff in and out of R. How do you get the initial .pdf file that you're manipulating here? I tried saving the R graphic to a PDF on my desktop and then running pdf (file = C:/Documents and Settings/aelmore/Desktop/foo.pdf, height = 15, width = 20) plot (foo) dev.off() You need to put the filename in quotes file = C:/Documents and Settings/aelmore/Desktop/foo.pdf Hope this is helpful, Dan but that netted me the error: unexpected '/' in pdf(file = C:/ and of course trying it without the string returned the error: object foo not found. What am I missing? Is the graphic that R displays when I call for a plot somehow available for use here? If so, I don't know what it's called/how to access it. The name of the regression tree that it represents doesn't work. That attempt gave me the error: cannot coerce type 'S4' to vector of type 'character.' So, as you see, closer but still stuck. Thanks again in advance for any assistance. Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Simple question about data.frame reduction
You need to reverse the order of variable 2 and 3 tapply(test$var3,test$var2,length) hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ronaldo Reis Júnior Sent: Tuesday, September 01, 2009 4:43 PM To: R-Help Subject: Re: [R] Simple question about data.frame reduction Dear Jorge, I already try this solution. But I need to retrieve the information in function of var3 and not var2, but excluding repeated measure in var2. tapply(test$var2,test$var3,length) a1 b1 c1 d1 3 1 1 1 but in a1 I need the result=2 and not 3 because two elements in var2 are repeated Thanks Ronaldo Em Ter 01 Set 2009, Jorge Ivan Velez escreveu: Dear Ronaldo, You were almost there! Here is a suggestion: with(test, tapply(var3, var2, length)) # a b c d e # 2 1 1 1 1 HTH, Jorge 2009/9/1 Ronaldo Reis Júnior Hi, this is a simple question I have this data.frame: test - data.frame(var1=c(1,1,1,1,1,1),var2=c(a,a,b,c,d,e),var3=c(a1 ,a1,b1,a1,c1,d1)) test var1 var2 var3 11a a1 21a a1 31b b1 41c a1 51d c1 61e d1 Then I need to calculate the number of var3 excluding the repeated measure of var2. With tapply I have this: tapply(test$var1,test$var3,sum) a1 b1 c1 d1 3 1 1 1 But the correct result is: a1 b1 c1 d1 2 1 1 1 because on factor a1 in var3 I have 2 repeated factor a in var2. I try a simple solution for it but without success. aggregate function dont work with factors (var3 by var1). Anybody have an idea? Thanks Ronaldo -- It's men like him that give the Y chromosome a bad name. -- Prof. Ronaldo Reis Júnior | .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional | | : :' : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia | | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8192 | ronaldo.r...@unimontes.br | chrys...@gmail.com | http://www.ppgcb.unimontes.br/lecc | ICQ#: 5692561 | LinuxUser#: 205366 -- Favor NÃO ENVIAR arquivos do Word ou Powerpoint Prefira enviar em PDF, Texto, OpenOffice (ODF), HTML, or RTF. __ 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. -- Pe�o paci�ncia aos impacientes que desejam meu desaparecimento: j� est� faltando menos que antes. -- Jacinto Benavente -- Prof. Ronaldo Reis Júnior | .''`. UNIMONTES/DBG/Lab. Ecologia Comportamental e Computacional | : :' : Campus Universitário Prof. Darcy Ribeiro, Vila Mauricéia | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8192 | ronaldo.r...@unimontes.br | chrys...@gmail.com | http://www.ppgcb.unimontes.br/lecc | ICQ#: 5692561 | LinuxUser#: 205366 -- Favor NÃO ENVIAR arquivos do Word ou Powerpoint Prefira enviar em PDF, Texto, OpenOffice (ODF), HTML, or RTF. [[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 while keeping distribution of nearest neighbor distances constant.
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Emmanuel Levy Sent: Wednesday, August 12, 2009 3:05 PM To: r-h...@stat.math.ethz.ch Cc: dev djomson Subject: [R] Random sampling while keeping distribution of nearest neighbor distances constant. Dear All, I cannot find a solution to the following problem although I imagine that it is a classic, hence my email. I have a vector V of X values comprised between 1 and N. I would like to get random samples of X values also comprised between 1 and N, but the important point is: * I would like to keep the same distribution of distances between the X values * For example let's say N=10 and I have V = c(3,4,5,6) then the random values could be 1,2,3,4 or 2,3,4,5 or 3,4,5,6, or 4,5,6,7 etc.. so that the distribution of distances (3 - 4, 3 -5, 3 - 6, 4 - 5, 4 - 6 etc ...) is kept constant. I couldn't find a package that help me with this, but it looks like it should be a classic problem so there should be something! Many thanks in advance for any help or hint you could provide, All the best, Emmanuel Emmanuel, I don't know if this is a classic problem or not. But given your description, you write your own function something like this sample.dist - function(vec, Min=1, Max=10){ diffs - c(0,diff(vec)) sum_d - sum(diffs) sample(Min:(Max-sum_d),1)+cumsum(diffs) } Where Min and Max are the minimum and maximum values that you are sampling from (Min=1 and Max=10 in your example), and vec is passed the vector that you are sampling distances from. This assumes that your vector is sorted smallest to largest as in your example. The function could be changed to accommodate a vector that isn't sorted. V - sort(sample(1:100,4)) V #[1] 46 78 82 95 sample.dist(V, Min=1, Max=100) #[1] 36 68 72 85 sample.dist(V, Min=1, Max=100) #[1] 12 44 48 61 This should get you started at least. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 while keeping distribution of nearest neighbor distances constant.
-Original Message- From: Emmanuel Levy [mailto:emmanuel.l...@gmail.com] Sent: Wednesday, August 12, 2009 4:48 PM To: Nordlund, Dan (DSHS/RDA) Cc: r-h...@stat.math.ethz.ch; dev djomson Subject: Re: [R] Random sampling while keeping distribution of nearest neighbor distances constant. Dear Daniel, Thank a lot for your suggestion. It is helpful and got me thinking more about it so that I can rephrase it: Given a vector V containing X values, comprised within 1 and N. I'd like to sample values so that the *distribution* of distances between the X values is similar. There are several distributions: the 1st order would be given by the function diff. The 2d order distribution would be given by diff(V[seq(1,length(V),by=2)]) and diff(V[seq(2,length(V),by=2)]) The 3rd order distribution diff(V[seq(1,length(V),by=3)]) and diff(V[seq(2,length(V),by=3)]) and diff(V[seq(3,length(V),by=3)]) The 4th order I would like to produce different samples, where the first, or first and second, or first and second and third, or up to say five orders distance distributions are reproduced. Is anybody aware of a formalism that is explained in a book and that could help me deal with this problem? Or even better of a package? Thanks for your help, Emmanuel But if the 1st order differences are the same, then doesn't it follow that the 2nd, 3rd, ... order differences must be the same between the original and the new random vector. What am I missing? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] matrix power
Cindy, I dont know of a better way to do this than what Ted Harding showed. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 From: cindy Guo [mailto:cindy.g...@gmail.com] Sent: Monday, August 10, 2009 7:05 PM To: Nordlund, Dan (DSHS/RDA) Cc: r-help@r-project.org Subject: Re: [R] matrix power Hi, Dan, Yes, this is what I want. Is there better way to solve this? Cindy On Mon, Aug 10, 2009 at 2:52 PM, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of cindy Guo Sent: Monday, August 10, 2009 2:32 PM To: r-help@r-project.org Subject: [R] matrix power Hi, All, If I have a symmetric matrix, how can I get the negative square root of the matrx, ie. X^(-1/2) ? Thanks, Cindy Cindy, Just to be sure we are all on the same page. Are saying you have a matrix X, and you want to find the a matrix A such that X = A %*% A And you want to then find the matrix inverse of A ? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 [[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] Bug in seq (or a feature) ?
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tal Galili Sent: Monday, August 10, 2009 2:14 PM To: r-help@r-project.org Subject: [R] Bug in seq (or a feature) ? (I use R 2.9.1 with win XP) If I run this code: seq(-0.1,.9, by = .05)[seq(-0.1,.9, by = .05) = 0.5] I get this output: [1] -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 Why is 0.50 not in the results ? (It seems that it gives a slightly bigger number then 0.5 but I don't understand why it does that) Where as if I try: seq(-0.1,.9, by = .05)[seq(-0.1,.9, by = .05) = 0.4] and get: [1] -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 Then 0.40 WILL be in the results. Thanks,Tal This is another question for which the answer is FAQ 7.31. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] matrix power
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of cindy Guo Sent: Monday, August 10, 2009 2:32 PM To: r-help@r-project.org Subject: [R] matrix power Hi, All, If I have a symmetric matrix, how can I get the negative square root of the matrx, ie. X^(-1/2) ? Thanks, Cindy Cindy, Just to be sure we are all on the same page. Are saying you have a matrix X, and you want to find the a matrix A such that X = A %*% A And you want to then find the matrix inverse of A ? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 selecting rows meeting a criterion
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Bouldin Sent: Monday, August 10, 2009 4:44 PM To: John Kane; r-help@r-project.org Subject: Re: [R] problem selecting rows meeting a criterion What's wrong is I'm trying to select only those rows in which X Y, but I'm getting rows in which Y X and losing some in which X Y. The row numbers are not being read as values. Very confusing. Jim What's wrong with it? It looks okay to me. If you use subset(data, data$X data$Y)you get the same results. Any chance you're reading the row.numbers as values? BTW data is a reserved word in R and it is good practice not to use it as a variable name. My Results X Y V3 3 3 1 2.236068 4 4 1 6.324555 5 5 1 5.00 6 1 2 8.062258 10 5 2 5.656854 11 1 3 2.236068 12 2 3 9.486833 17 2 4 2.236068 18 3 4 8.062258 24 4 5 5.385165 --- On Mon, 8/10/09, Jim Bouldin jrboul...@ucdavis.edu wrote: From: Jim Bouldin jrboul...@ucdavis.edu Subject: [R] problem selecting rows meeting a criterion To: r-help@r-project.org Received: Monday, August 10, 2009, 5:49 PM When I try to select only those rows from the following data frame, called data, in which X Y X Y V3 2 2 1 8.062258 3 3 1 2.236068 4 4 1 6.324555 5 5 1 5.00 6 1 2 8.062258 8 3 2 9.486833 9 4 2 2.236068 10 5 2 5.656854 11 1 3 2.236068 12 2 3 9.486833 14 4 3 8.062258 15 5 3 5.099020 16 1 4 6.324555 17 2 4 2.236068 18 3 4 8.062258 20 5 4 5.385165 21 1 5 5.00 22 2 5 5.656854 23 3 5 5.099020 24 4 5 5.385165 using the commands attach(data) data2 = data[X Y,];data2 I get this for data2: X Y V3 3 3 1 2.236068 4 4 1 6.324555 5 5 1 5.00 6 1 2 8.062258 10 5 2 5.656854 11 1 3 2.236068 12 2 3 9.486833 17 2 4 2.236068 18 3 4 8.062258 24 4 5 5.385165 Clearly, this is not what I intend but I cannot figure out what I've done wrong. Any help appreciated. Thanks. Jim Bouldin Jim, I copied your data to a text file and read it in using read.table(). Your code worked as expected for me. So, your problem is not reproducible. Is it possible that your data frame has been corrupted? What does str(data) show you? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] hi, i have a problem in R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gina Liao Sent: Wednesday, August 05, 2009 7:15 AM To: r-h...@stat.math.ethz.ch Subject: [R] hi, i have a problem in R Hi, I'm new to R language. There is a problem I couldn't understand. Hope you can answer my question. when i type for (i in 1:10){ + print(sample(9,4,replace=T)) +} and it shows ten of four numbers and how do I do to calculate the frequencies in each list? I know there is a hint; list10-vector(mode=list,length=4) But I don't know how to use it. How do I name each list? There are my problems. Thanks!! Best Regards, vie It is not clear to me what you are trying to calculate frequencies for. Are you trying to get 10 sets of 4 random digits, or 4 sets of ten random digits? What frequencies are you trying to calculate? To generate 10 rows of 4 digits I would probably do something like digits - matrix(sample(9,40,replace=T), nrow=10) Then you could get frequencies of digits by row or by column. But I am not sure what you want. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] One critical question in R
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Hyo Karen Lee Sent: Tuesday, August 04, 2009 8:21 AM To: r-help@r-project.org Subject: [R] One critical question in R Hi, I have one critical question in using R. I am currently working on some research which involves huge amounts of data(it is about 15GB). I am trying to use R in this research rather than using SAS or STATA. (The company where I am working right now, is trying to switch SAS/STATA to R) As far as I know, the memory limit in R is 4GB; The memory limit depends on your hardware and OS which you haven't told us about. With Linux and a 64-bit computer the limit MUCH higher. With 32-bit MS Windows OS you won't likely get even 3GB. However, I believe that there are ways to handle the large dataset. You can use a database program like MySQL for example. If you have files that are on the order of 15GB in size, I don't thinlk you are going to have much success cleaning the data use R (well I know I wouldn't, but maybe one of the experts here can help you out). You may be able to use the biglm package for analuses, or read in just the data you need for your regressions. If you more help you will need to tell us more about what your data is like, with more specifics about what your analyses will look like. Most of my works in R would be something like cleaning the data or running a simple regression(OLS/Logit) though. The whole company relies on me when it comes to R. Please teach me how to deal with large data in R. If you can, please give me a response very soon. Thank you very much. Regards, Hyo Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] saving only part of a computation in integrate
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Mary A. Marion Sent: Thursday, July 30, 2009 12:56 PM To: r-help@r-project.org Subject: [R] saving only part of a computation in integrate Hello, I am using Beta -integrate(dnorm,mean=0,sd=1,-Inf,2.3552) Beta 0.9907436 with absolute error 4.2e-06 1-Beta results in an error How can I store into Beta only .9907436? Thank you. Sincerely, Mary A. Marion Take a look at the results of str(Beta) List of 5 $ value : num 0.99 $ abs.error : num 4.22e-06 $ subdivisions: int 4 $ message : chr OK $ call: language integrate(f = dnorm, lower = -Inf, upper = 2.3552, mean = 0, sd = 1) - attr(*, class)= chr integrate So it would appear that you could do Beta -integrate(dnorm,mean=0,sd=1,-Inf,2.3552)$value Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] for loop for file names
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of waltzmiester Sent: Thursday, July 30, 2009 1:29 PM To: r-help@r-project.org Subject: Re: [R] for loop for file names Thanks very much for these two solutions, but they are still printing Pred_pres_[i]_indpdt on the screen and not executing the function load Chris baptiste auguie-5 wrote: Try this, files = paste('pred/Pred_pres_', letters[1:6], '_indpdt',sep=) lapply(files, load) HTH, baptiste 2009/7/30 waltzmiester cwalt...@shepherd.edu: I am trying to load binary files in the following fashion load(pred/Pred_pres_a_indpdt) load(pred/Pred_pres_b_indpdt) load(pred/Pred_pres_c_indpdt) load(pred/Pred_pres_d_indpdt) load(pred/Pred_pres_e_indpdt) load(pred/Pred_pres_f_indpdt) but I would like to set up a for loop to replace the letters a:f Here is what I have so far: letter=c(a,b,c,d,e,f) for(l in letter){ cat(load('pred/Pred_pres_,l,_indpdt'),sep=,collapse=,\n) } That will print the above commands to the console but it will not actually enter the commands. Any ideas? Thanks Chris -- View this message in context: http://www.nabble.com/for-loop-for-file-names-tp24746012p24746012.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. -- _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK http://newton.ex.ac.uk/research/emag __ 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. How about files = paste('pred/Pred_pres_', letters[1:6], '_indpdt',sep=) for(i in files){load(i)} Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] install package from CRAN
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of cindy Guo Sent: Tuesday, July 28, 2009 5:36 PM To: Steve Lianoglou Cc: r-help@r-project.org Subject: Re: [R] install package from CRAN Hi, Steve, Thanks for the response. I did the same thing: install.packages('mvtnorm') -bash: syntax error near unexpected token `'mvtnorm'' I think what may cause difference is that I am using a unix cluster of my university, so I am not the administrator. Do I need to set the path? Cindy The error you are getting is from the bash shell. Are you trying to run the command from the shell, or from inside R? You need to start R and then run install.packages('mvtnorm') from the R terminal. You still may have permission problems, and I think you will need to have installed and have access to the appropriate tools for building packages. Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] error message: .Random.seed is not an integer vector but
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Bouldin Sent: Thursday, July 23, 2009 9:49 AM To: ted.hard...@manchester.ac.uk; ted.hard...@manchester.ac.uk; r-h...@r- project.org Subject: Re: [R] error message: .Random.seed is not an integer vector but Thanks much Ted. I actually had just tried what you suggest here before you posted, and resolved the problem. Thanks also for the other tips. I wrote x = as.vector(c(1:12)) because I thought that the mode of x might be the problem, the error message pointing to .Random.seed notwithstanding. On a related note, I did a brief test a couple weeks back where I ran a million random samples of 3 from the vector 1:12 and compared the mean against the known mean. It was off by 1 percent, which indicated that the RNG was biased more than I'd have thought. Comments? Jim snip It would be necessary to see the code for your 'brief test' before anyone could meaningfully comment on your results. But your results for a single test could have been a valid random result. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Sample Function
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of MarcioRibeiro Sent: Thursday, July 16, 2009 8:56 AM To: r-help@r-project.org Subject: [R] Sample Function Hi listers, Suppose I have a dataset with n=10 observations and I want to sample with replacement. My new sample is of size m=9. So, I am using the following code... newsample-dataset[sample(m,replace=T),] The problem is that generates the new sample and the last observation of my data set is never included. I can sample the identification like this code... newsample-sample(1:n,m,replace=TRUE) But, after this code I am obtaining a statistic and I have only the identification of the data observed. Is there a way that I can sample the data observed to calculate a statistic of it. Thanks in advance, Marcio Try newsample-dataset[sample(1:10,m,replace=TRUE),] Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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 use current value of variable in function definition?
Alan, Doesn't Peter Dalgaard's response get you what you originally asked for? You said you wanted something like: if (1) { c - 1; foo - function () print(c); } c - 2 foo() Based on Peter's email you could do c - 1 foo - local({x - c; function() print(x) }) foo() [1] 1 c - 2 foo() [1] 1 Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of William Dunlap Sent: Thursday, July 02, 2009 2:44 PM To: Allan Engelhardt Cc: r-help@r-project.org Subject: Re: [R] How to use current value of variable in function definition? From: Allan Engelhardt [mailto:all...@cybaea.com] Sent: Thursday, July 02, 2009 11:12 AM To: William Dunlap Cc: r-help@r-project.org Subject: Re: [R] How to use current value of variable in function definition? Thanks for the pointer to substitute(), William. This seems to work and is a little shorter than yours: a - 1; foo - eval(substitute(function () print(a), env=list(a=a))) a - 2; foo() # [1] 1 Not the clearest code I have ever seen, especially as 'foo' still shows 'a': print(foo) # function () a Allan The need for eval and the misleading printout is why I sent the longer version. functionBody(foo) does show the right thing. One might consider this a bug in substitute(): it does not clear out the source information when it works on a call to function. You can add attr(foo,source)-NULL to fix up the printing. substitute() doesn't seem to go into the default values of the arguments, which is where one might prefer to put variables like this. The eval() around substitute() is needed because function(z)z+1 is a call to a function called function, it is not a function until that call gets evaluated and substitute does not evaluate its first argument). Using local() avoids these problems. Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap tibco.com On 02/07/09 18:28, William Dunlap wrote: From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Allan Engelhardt Sent: Thursday, July 02, 2009 9:47 AM To: r-help@r-project.org Subject: [R] How to use current value of variable in function definition? Must be the heat or something but I can't get my brain into gear and figure out how to get something like if (1) { c - 1; foo - function () print(c); } c - 2 foo() to print 1, not 2. (The real life example is a little more complex, but you get the idea. I don't want the variable c in the function definition, I want its value at that time.) The only thing I have been able to come up with is something like if (1) foo - (function () { c - 1; return(function () print(c)) })() c - 2 foo() # [1] 1 You might try local(), as in c-1 ; foo.local-local({orig.c - c ; function()orig.c}) foo.local() [1] 1 c-3 foo.local() [1] 1 It is possible for someone to alter the orig.c after you create foo.local, as in assign(orig.c, 17, env=environment(foo.local)) foo.local() [1] 17 Looking at the function's code will not make it clear where orig.c is coming from. The clue is that its environment is not one of the standard named ones, but it given by a hex number. foo.local function()orig.c environment: 0x02108c54 You could also use substitute() to change the code in the function. It can be messy to do but the resulting code may be clearer (although it won't give a hint as to where that constant came from). E.g., foo.substitute-function()orig.c c-1 ; functionBody(foo.substitute)-do.call(substitute, list(functionBody(foo.substitute), list(orig.c=c))) foo.substitute() [1] 1
Re: [R] sorting question
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Steve Jaffe Sent: Wednesday, July 01, 2009 9:59 AM To: r-help@r-project.org Subject: [R] sorting question I've asked about custom sorting before and it appears that -- in terms of a user-defined order -- it can only be done either by defining a custom class or using various tricks with order Just wondering if anyone has a clever way to order vintages of the form 2002, 2003H1, 2003H2, 2004, 2005Q1, 2005Q2, etc some have H1 or H2, some have Q1,Q2,Q3,Q4, some are just plain years. They should be sorted in the obvious order. I can think of doing something with s'trsplit' and 'order' but anyone have anything better? Steve, I don't have a solution to your sort problem, but let me ask: what is the obvious order is in this situation? Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 (I still wonder why sorting with a user-defined function isn't supported. I guess I should follow the open source philosophy and contribute my own, but it seems that would involve implementing an explicit, iterative sort algorithm, whereas it would make more sense for it to be integrated with the internal sort function, if that were possible) Thanks -- View this message in context: http://www.nabble.com/sorting-question- tp24293430p24293430.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.
Re: [R] Random number datasets help
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Sent: Thursday, June 18, 2009 10:52 AM To: Alexandre Lockhart Cc: r-help@r-project.org Subject: Re: [R] Random number datasets help Try this also: a - expand.grid(a1, a2) x - mapply(rnorm, n = 500, mean = a[,1], sd = a[,2]) On Thu, Jun 18, 2009 at 2:10 PM, Alexandre Lockhart alexandre_geor...@hotmail.com wrote: Hello: My problem is that I have a data frame of means, and a data frame of standard deviations which match up to each mean. I have been trying to create 500 random numbers in a given dataset for each mean/sd combination, but I am only able to generate the last value in each data set to create one dataset (there should be 28 in all). Examining my code, what can I change to generate 28 datasets based on respective mean and sds? a1- c(178.07,178.28,178.08,177.74,177.04,178.17,177.58,57.71,59.6,60.92,59.48,59.32, 61.59,59.94,28.9,29.82,30.73,25.68,27.93,28.98,29.76,123.48,127.27,127.8,127.2,1 27.13,126.71,125.5) a2- c(1.69,1.3,1,.18,1.53,1.31,1.35,1.83,1.56,1.12,.74,1.48,1.67,1.53,.95,.87,0.03,1.12,1. 95,1.22,1.04,1.64,1.83,1,1,1.08,1.35,2.37) for(i in 1:length(a1)) for(j in 1:length(a2)) x-rnorm(500,mean=a1[i],sd=a2[j]) Thank you, Agl _ Microsoft brings you a new way to search the web. Try Bing™ now gline_try bing_1x1 [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O Since the original post said that he wanted 28 samples of 500, what may be wanted is x - mapply(rnorm, n = 500, mean = a1, sd = a2) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Installing R on Ubuntu 8.10
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Maria I. Tchalakova Sent: Saturday, May 16, 2009 2:37 AM To: R-help Forum Subject: [R] Installing R on Ubuntu 8.10 Hi, I am trying to install R on Ubuntu 8.10. I have added this line: deb http://cran.at.r-project.org/bin/linux/ubuntu intrepid/ in my /etc/apt/sources.list file. However when I Reload, I get the following error message: W: GPG error: http://cran.at.r-project.org intrepid/ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D67FC6EAE2A11821 I have tried different mirror sites, but the result is the same. There is nothing written about public keys on the download page: http://cran.at.r-project.org/ Then, I have tried (after I added the line to the /etc/apt/sources/list file) not pressing Reload, but Close, and I have written in the console: sudo apt-get update but I received similar message again: Reading package lists... Done W: GPG error: http://cran.rakanu.com intrepid/ Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D67FC6EAE2A11821 W: You may want to run apt-get update to correct these problems Do you know what the problem is, and what should I do? Thanks in advance. Maria Maria, Go to the CRAN website (or your preferred mirror), select Linux under the download and install section, then select Ubuntu, and read what it says about installation. http://cran.r-project.org/ Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Problems with randomly generating samples
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Debbie Zhang Sent: Wednesday, May 13, 2009 8:18 AM To: r-help@r-project.org Subject: [R] Problems with randomly generating samples Dear R users, Can anyone please tell me how to generate a large number of samples in R, given certain distribution and size. For example, if I want to generate 1000 samples of size n=100, with a N(0,1) distribution, how should I proceed? (Since I dont want to do rnorm(100,0,1) in R for 1000 times) Thanks for help Debbie How about samples - rnorm(1000*100,0,1) dim(samples) - c(1000,100) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] Floating simulation error
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Brendan Morse Sent: Thursday, April 23, 2009 9:12 AM To: r-help@r-project.org Subject: [R] Floating simulation error Hi all, I am running a simulation and a curious error keeps coming up that stops the whole process. The error is a subscript out of bounds error, and it seems to happen at different points (floating around) throughout the looping simulation. Say, for example, it crashes on sample 1 - iteration 200. I can force it to start again on iteration 202 with all of the same settings, and it is fine. I can also force it to start again on iteration 201 if I modify the starting seed value and it goes on its merry way. What I think is happening is that certain seed values are disrupting something and causing the subscript error. My seeds are set as follows: The simulation has x number of conditions. The starting seeds are set to equal the condition number (1 to x). The program runs 500 iterations within each condition, and the seed values for each iteration are set as x+iteration number. So, for condition 1, iteration 1, the starting seed value would be 2, then 3 etc. etc. At some point, I will get the subscript error but it seems unpredictable. Has anyone had a similar problem or an idea as to what might be happening? - Brendan Brendan, This is one of those situations where a self-contained, reproducible example would be really helpful. In the absence of that, seeing your actual code is absolutely necessary. I can't imagine anyone being able to provide any useful help here otherwise. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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.