[R] regex sub with specified number of characters

2015-10-06 Thread Johannes Radinger
Hi I'd like to remove a leading "3" if my number is 7 digits long, if it is only 6 I don't want to anything. I think this should be possible with a 1-liner using sub() but I am not sure how to define the number of characters following the leading one. For example my vector: a <-

Re: [R] regex sub with specified number of characters

2015-10-06 Thread Ivan Calandra
Hi Johannes, Not sure if this can be done with sub() only, but combining it with ifelse() apparently does what you want: ifelse(nchar(a)==7, sub("^3","",a), a) HTH, Ivan -- Ivan Calandra, PhD University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100

Re: [R] regex sub with specified number of characters

2015-10-06 Thread Marc Schwartz
> On Oct 6, 2015, at 9:38 AM, Johannes Radinger > wrote: > > Hi > > I'd like to remove a leading "3" if my number is 7 digits long, if it is > only 6 I don't want to anything. > I think this should be possible with a 1-liner using sub() but I am not > sure how to

Re: [R] Strange Bug in R

2015-10-06 Thread David L Carlson
There is a simple way to get closer to how a floating point number is stored in R with dput(): > dput(min(dataset$gpa)) 1.8997615814 > dput(dataset$gpa[290]) 1.8997615814 So you can see, the minimum is not 1.9, just very close to 1.9. - David L

Re: [R] regex sub with specified number of characters

2015-10-06 Thread David Winsemius
On Oct 6, 2015, at 7:38 AM, Johannes Radinger wrote: > Hi > > I'd like to remove a leading "3" if my number is 7 digits long, if it is > only 6 I don't want to anything. > I think this should be possible with a 1-liner using sub() but I am not > sure how to define the number of characters

Re: [R] R implementation on windows server

2015-10-06 Thread Duncan Murdoch
On 06/10/2015 1:25 PM, Sharique Alam wrote: Hi Team, We are required to install r on a windows server Request you to kindly help us in below queries: 1> Pre requisite for installing R if any There are none. 2> Do we have to install R and R studio both R Studio is a separate product; it

Re: [R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
Almost forgot that function lmfunc is this: lmfunc = function(valist,input){ fitted.values(lm(valist~input)) } A On Tue, Oct 6, 2015 at 2:41 PM, Adrienne Wootten wrote: > FYI I did try something like this: > > test = apply(test3,c(1,2),lmfunc,input=t) > > but that gives

Re: [R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
FYI I did try something like this: test = apply(test3,c(1,2),lmfunc,input=t) but that gives me an array that is 10 rows by 5 columns by 5 slices, and I need it to keep the same dimensions as test3 (5x5x10) A On Tue, Oct 6, 2015 at 1:42 PM, Adrienne Wootten wrote: >

[R] variance of beta using prop.odds function in timereg package

2015-10-06 Thread lspirk
Hi all, I am trying to calculate the variance-covariance matrix for parameter Beta under the null (Ho) using the "prop.odds" function in the timereg package. For the Cox PH model, I used the "vcov" function and did the following: cox <- coxph(Surv(time, censor) ~ x, iter = 0, init = 0,

[R] Strange Bug in R

2015-10-06 Thread Neverstop
Hi all. I don't understand why R works this way: > rm(list=ls()) > require(foreign) > dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;) > min(dataset$gpa) [1] 1.9 > min(dataset$gpa)>=1.90 [1] FALSE > min(dataset$gpa)>=1.9 [1] FALSE > min(dataset$gpa)>1.89 [1] TRUE Shouldn't I get

Re: [R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
Bill, Thanks a bunch that works great! A On Tue, Oct 6, 2015 at 2:56 PM, William Dunlap wrote: > Since the model matrix, cbind(1,time) is the same for all your > response variables, > you can calculate this on one call to lm, but you have to rearrange the > response >

[R] cut - strange NA as output

2015-10-06 Thread Hermann Norpois
Hello, why do I get NA for the following: cut (x, seq (0, max(x), by=1), label=FALSE) [1] 1322 1175 1155 1149 1295 1173 1289 1197 NA 1129 dput (x) c(1321.55376901374, 1174.35657200935, 1154.02042504008, 1148.60981925942, 1294.6166388941, 1172.45806806869, 1288.31933914639, 1196.26080041462,

Re: [R] cut - strange NA as output

2015-10-06 Thread William Dunlap
Because > tail(seq(0, max(x), by=1)) [1] 1350 1351 1352 1353 1354 1355 > tail(seq(0, ceiling(max(x)), by=1)) [1] 1351 1352 1353 1354 1355 1356 and max(x)=1355.88836502166 is beyond the range of the former. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Oct 6, 2015 at 12:20 PM,

Re: [R] cut - strange NA as output

2015-10-06 Thread Olivier Crouzet
Hi, On Tue, 6 Oct 2015 21:20:13 +0200 Hermann Norpois wrote: > Hello, > > why do I get NA for the following: > > cut (x, seq (0, max(x), by=1), label=FALSE) > [1] 1322 1175 1155 1149 1295 1173 1289 1197 NA 1129 The NA comes from your max value and it's due to your

Re: [R] cut - strange NA as output

2015-10-06 Thread Marc Schwartz
> On Oct 6, 2015, at 2:20 PM, Hermann Norpois wrote: > > Hello, > > why do I get NA for the following: > > cut (x, seq (0, max(x), by=1), label=FALSE) > [1] 1322 1175 1155 1149 1295 1173 1289 1197 NA 1129 > > dput (x) > c(1321.55376901374, 1174.35657200935,

Re: [R] help with problem

2015-10-06 Thread David L Carlson
You have a warning, not an error. The command ran but there was a problem with the .csv or .txt file. You should have a partial data set in R. Try using the str() function to see what variables and what rows were read. Adding the fill=TRUE argument to read.table() will pad incomplete rows

Re: [R] vector graphics

2015-10-06 Thread Adams, Jean
Perhaps the discussion at this link will be helpful ... http://stackoverflow.com/questions/9555889/producing-a-vector-graphics-image-i-e-metafile-in-r-suitable-for-printing-in Jean On Tue, Oct 6, 2015 at 9:42 AM, Ivan Calandra wrote: > Dear useRs, > > A colleague

Re: [R] apply regression to an array

2015-10-06 Thread David Winsemius
On Oct 6, 2015, at 10:42 AM, Adrienne Wootten wrote: > R-Helpers, > > I've seen some similar threads about this question online, but not quite > what I'm looking for. I apologize in advance if someone's already answered > this and I just can't find it online. > > Say that I have an array like

Re: [R] count by category

2015-10-06 Thread Thierry Onkelinx
Here is a solution using dplyr. dataset <- data.frame( region = rep(1:2, c(6, 1)), city = rep(1:2, c(5, 2)), town = rep(1:2, c(4, 3)), district = rep(1:3, c(2, 2, 3)) ) library(dplyr) dataset %>% group_by(region) %>% mutate(n.region = n()) %>% group_by(city, add = TRUE) %>%

Re: [R] count by category

2015-10-06 Thread Jim Lemon
Hi Val, You can even get a graphic illustration of this quite easily: library(plotrix) sizetree(dataset) Jim On Tue, Oct 6, 2015 at 10:00 AM, Val wrote: > Hi All, > > I have a data set ( region, city, town and district). The data looks like > region, city, town,

Re: [R] Strange Bug in R

2015-10-06 Thread Rolf Turner
On 06/10/15 20:24, Neverstop wrote: Hi all. I don't understand why R works this way: rm(list=ls()) require(foreign) dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;) min(dataset$gpa) [1] 1.9 min(dataset$gpa)>=1.90 [1] FALSE min(dataset$gpa)>=1.9 [1] FALSE

Re: [R] Strange Bug in R

2015-10-06 Thread Berend Hasselman
> On 6 Oct 2015, at 09:24, Neverstop wrote: > > Hi all. > I don't understand why R works this way: >> rm(list=ls()) >> require(foreign) >> dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;) >> min(dataset$gpa) > [1] 1.9 >> min(dataset$gpa)>=1.90 > [1]

Re: [R] Strange Bug in R

2015-10-06 Thread Rolf Turner
On 06/10/15 21:28, Berend Hasselman wrote: On 6 Oct 2015, at 09:24, Neverstop wrote: Hi all. I don't understand why R works this way: rm(list=ls()) require(foreign) dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta;) min(dataset$gpa) [1] 1.9

Re: [R] help with problem

2015-10-06 Thread Sarah Goslee
http://stackoverflow.com/questions/5990654/incomplete-final-line-warning-when-trying-to-read-a-csv-file-into-r On Tue, Oct 6, 2015 at 11:14 AM, Marco Otoya Chavarria wrote: > *When i tried to read a table i**n .csv or .txt format R i get the > following message and

Re: [R] Getting monthly mean

2015-10-06 Thread Sarah Goslee
There are various tools available; searching for netcdf on rseek.org or browsing CRAN will get you quite a few. Meanwhile this might help you get started: http://disc.sci.gsfc.nasa.gov/recipes/?q=recipes/How-to-Read-Data-in-netCDF-Format-with-R Sarah On Tue, Oct 6, 2015 at 11:31 AM, timilsina

[R] R implementation on windows server

2015-10-06 Thread Sharique Alam
Hi Team, We are required to install r on a windows server Request you to kindly help us in below queries: 1> Pre requisite for installing R if any 2> Do we have to install R and R studio both 3> Users also want to utilize shiny package ,so do we only need to install shiny package or will have

Re: [R] apply regression to an array

2015-10-06 Thread William Dunlap
Since the model matrix, cbind(1,time) is the same for all your response variables, you can calculate this on one call to lm, but you have to rearrange the response values so that each x,y set is in one column. I think the following function does it: f <- function (time, y) {

[R] Installing pre-compiled R in Linux

2015-10-06 Thread Sasikumar Kandhasamy
Hi, I have downloaded the pre-compiled version of R package: r-base-core(3.2.2-1) for i386 platform. Unzipped the package under my tmp directory (/tmp). The directories "et"c and "usr" got created with binaries R and Rscript under /tmp/usr/bin/. Executing the R (/tmp/usr/bin/R) or Rscript

Re: [R] Measure the frequencies of pairs in a matrix

2015-10-06 Thread Boris Steipe
Since order is not important to you, you can order your pairs (e.g. decreasing) before compiling the frequencies. But I don't understand the second part about values "that do not appear in the matrix". Do you mean you want to assess all combinations? If that's the case I would think about a

Re: [R] Installing pre-compiled R in Linux

2015-10-06 Thread Michael Hannon
It's very likely that there is already an R package for your linux system, and, if so, you'd probably be well-served to use that one. You've given us the version of the kernel you're using (not a recent one, BTW), but what linux distribution are you using? -- Mike On Tue, Oct 6, 2015 at 3:59

Re: [R] Result error using the function

2015-10-06 Thread Adams, Jean
I have simplified your function. And I have transposed your results such that resulting metrics are in columns rather than rows. So, it's not exactly what you were after, but perhaps you will find it useful. monthly_summary <- function(dt, r, tol=1E-6) { # number of days with above tol by

Re: [R] Strange Bug in R

2015-10-06 Thread Pascal Oettli
Hello, 1) Please don't put rm(list=ls()) in a script you submit to this list. This is considered as bad manner. 2) Please read https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f and http://stackoverflow.com/a/9508558/3710546 Regards, Pascal On

[R] Measure the frequencies of pairs in a matrix

2015-10-06 Thread Hermann Norpois
Hello, I have a matrix mat (see dput(mat)) > mat [,1] [,2] [1,]56 [2,]65 [3,]54 [4,]55 I want the frequencies of the pairs in a new matrix, whereas the combination 5 and 6 is the same as 6 and 5 (see the first two rows of mat). In other words:

Re: [R] Bug in auglag?

2015-10-06 Thread Ravi Varadhan
Dear Rainer, This is NOT a bug in auglag. I already mentioned that auglag() can work with infeasible starting values, which also implies that the function must be evaluable at infeasible values. A simple solution to your problem would be to fix up your objective function such that it

Re: [R] cut - strange NA as output

2015-10-06 Thread Hermann Norpois
Thanks this was very helpful. @Olivier Crouzet: Yes, round (x) would do the job but it was a principal confusion ... 2015-10-06 21:57 GMT+02:00 Marc Schwartz : > > > On Oct 6, 2015, at 2:20 PM, Hermann Norpois wrote: > > > > Hello, > > > > why do I get

Re: [R] help with problem

2015-10-06 Thread Sarah Hardy
It's possible that you have some invisible characters in the last line(s) of the csv file. You can use a text editor as Davis suggested or in Excel delete a bunch of the blank rows after the end of the data rows. If that doesn't work cut-and paste the rows you do want into a fresh spreadsheet.

[R] extract all dataframes from list

2015-10-06 Thread maicel
Hello List, I have list of named dataframe. How can I extract all dataframes from this list? The dataframe names should be the same of the original list. May I use the lapply function? Thanks for your help. Best regards, Maicel Monzon, MD National Center of Clinical Trials Havana, Cuba --

[R] Error Correction Model under Cointegration

2015-10-06 Thread Preetam Pal
Hi All, I have a time series y_t and 2 other time series x1_t and x2t as regressors. I know that these 3 series are cointegrated via the Johansen tests. Hence I want to implement an error correction model with 1 lag for each variable (i.e. Lag y, lag x1 and lag x2) for projection purposes

[R] Result error using the function

2015-10-06 Thread smart hendsome
Hi R-users, I am new to R.  I try to code using the function in R as below:  monthly_summary <- function(dt,r) {  tol <- 1E-6    mn  <- vector(length=12, mode="numeric")    lambda  <- vector(length=12, mode="numeric")    ag  <- aggregate(dt[,4] > tol, list (dt[,2], dt[,1]), sum)    names(ag) <-

Re: [R] Quantile Regression without intercept

2015-10-06 Thread Roger Koenker
> On Oct 6, 2015, at 8:32 AM, Lorenz, David wrote: > > Thanks for the details, I suspected something like that. > I think that begs the question: what is the meaning of quantile regression > through the origin? If the tau=.5 line does not pass through 1/2 the data how > do I

[R] Bug in auglag?

2015-10-06 Thread Rainer M Krug
Hi Ravi, I would like come back to your offer. I have a problem which possibly is caused by a bug or by something I don't understand: My function to be minimised is executed even when an element in hin() is negative. My hin looks as follow: --8<---cut

Re: [R] Quantile Regression without intercept

2015-10-06 Thread Lorenz, David
Thanks for the details, I suspected something like that. I think that begs the question: what is the meaning of quantile regression through the origin? If the tau=.5 line does not pass through 1/2 the data how do I interpret the line? On Tue, Oct 6, 2015 at 8:03 AM, Roger Koenker

Re: [R] Quantile Regression without intercept

2015-10-06 Thread peter dalgaard
To wit: > y <- rnorm(100, 10) > x <- 1:100 > sum(resid(lm(y~x))) [1] 1.047773e-15 > sum(resid(lm(y~x-1))) [1] 243.0583 and replicating this should convince you that the mean residual really is not zero in the severely misspecified model with no intercept. (This has to do with the fact that

Re: [R] Quantile Regression without intercept

2015-10-06 Thread Lorenz, David
Did you verify that the correct percentages were above/below the regression lines? I did a quick check and for example did not consistently get 50% of the observed response values greater than the tau=.5 line. I did when I included the nonzero intercept term. > Date: Mon, 5 Oct 2015 21:14:04

Re: [R] Bug in auglag?

2015-10-06 Thread Rainer M Krug
Please ignore - list members - accidentally CCd. Rainer Rainer M Krug writes: > Hi Ravi, > > I would like come back to your offer. I have a problem which possibly is > caused by a bug or by something I don't understand: > > My function to be minimised is executed even when an

Re: [R-es] Europa

2015-10-06 Thread miguel.angel.rodriguez.muinos
Hola Javier. El tema de la protección de datos de carácter personal es bastante complejo (y más si lo extiendes entre países). Veamos un resumen grosso modo (y algo inexacto) Cada país tiene su propia legislación sobre datos personale. Cuando estás trabajando con datos que identifiquen a

Re: [R] Quantile Regression without intercept

2015-10-06 Thread Roger Koenker
> On Oct 6, 2015, at 7:58 AM, Lorenz, David wrote: > > Did you verify that the correct percentages were above/below the regression > lines? I did a quick check and for example did not consistently get 50% of > the observed response values greater than the tau=.5 line. I did

Re: [R] Strange Bug in R

2015-10-06 Thread Neverstop
Thank you all very much for the explanations! -- View this message in context: http://r.789695.n4.nabble.com/Strange-Bug-in-R-tp4713175p4713182.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To

[R] help with problem

2015-10-06 Thread Marco Otoya Chavarria
*When i tried to read a table i**n .csv or .txt format R i get the following message and give some problem in orden to run the data o make test, etc* *Warning message* *In read.table(file = file, header = header, sep =";") *>* incomplete final line found by readTableHeader on 'test.csv* *I

[R] Polygon shade

2015-10-06 Thread bgnumis bgnum
Hi All, I want to shade the area below "f" variable and it doesn´t draw: plot(z$Dateh[nn:length(z$Dateh)],f,type="l",col="black", xlab="Time", ylab="Line") grid() polygon(c(1, 1:st, st),c(0, f, 0), col = "blue") st is the length of f. But if I plot plot(f,type="l",col="black", xlab="Time",

[R] Getting monthly mean

2015-10-06 Thread timilsina
Hi all, How can I get the monthly means from netcdf files using R? If there is any examples already on web resources? Please share with me. Regards, Amit -- View this message in context: http://r.789695.n4.nabble.com/Getting-monthly-mean-tp4713209.html Sent from the R help mailing list

[R] vector graphics

2015-10-06 Thread Ivan Calandra
Dear useRs, A colleague of mine is having a problem with graphic devices. The goal is to save into a vector graphic format that can be edited with Illustrator CS4. On my Mac (Snow Leopard), I use RSvgDevice::devSVG() and it works fine. But on her Windows Vista computer, I cannot find an

[R] apply regression to an array

2015-10-06 Thread Adrienne Wootten
R-Helpers, I've seen some similar threads about this question online, but not quite what I'm looking for. I apologize in advance if someone's already answered this and I just can't find it online. Say that I have an array like test3 in the little example code I have below: test1 =