FAQ

# R>r-help>October 2013

## 407 discussions - 1,295 posts

• 14

#### [R] Subseting a data.frame

Dear Forum, I have a data frame as mydat = data.frame(basel_asset_class = c(2, 8, 8 ,8), defa_frequency = c(0.15, 0.07, 0.03, 0.001)) basel_asset_class defa_frequency 1 2 0.150 2 8 0.070 3 8 0.030 4 ...
 Katherine GobinOct 17, 2013 at 6:55 amOct 18, 2013 at 12:58 pm
• 13

#### [R] Recovering object names when using the ... argument in a fn XXXX

Hi all, I am using the ... argument to parmeterize a user define fn to accept multiple input objects. I subsquently save all these data as a list. Question: what is the best way to recover or extract ...
 Dan AbnerOct 18, 2013 at 4:05 pmOct 21, 2013 at 7:13 pm
• 12

#### [R] labeling abscissa using a function of the plotted scale

Is it easy or difficult to label the abscissa of a scatter graph as 1/trueScaleValue at that point? -- View this message in context ...
 HurrOct 11, 2013 at 4:48 pmOct 24, 2013 at 11:14 pm
• 12

#### [R] XML package not working

I know I cannot be the only one who is not able to install the XML package from CRAN (zip or tar file) Many packages depend on this XML package. Can someone help me either access the source for a ...
 Steven Dwayne RandolphOct 19, 2013 at 7:47 pmOct 24, 2013 at 5:01 pm
• 12

#### [R] matrix values linked to vector index

Hi, In the example you showed: m1<- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or ?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1<- c(3,4,5) ?m2<- ...
 ArunOct 11, 2013 at 4:49 pmOct 13, 2013 at 2:22 pm
• 11

#### [R] speeding up "sum of squared differences" calculation

All, I am using a sum of squared differences in the objective function of an optimization problem I am doing and I have managed to speed it up using the outer function versus the nested for loops, ...
 Bos, RogerOct 21, 2013 at 8:30 pmOct 23, 2013 at 11:03 pm
• 11

#### [R] nlminb() - how do I constrain the parameter vector properly?

Greets, I'm trying to use nlminb() to estimate the parameters of a bivariate normal sample and during one of the iterations it passes a parameter vector to the likelihood function resulting in an ...
 Steven LeBlancOct 20, 2013 at 10:01 pmOct 21, 2013 at 5:33 pm
• 11

#### [R] Interpreting the result of a Wilcoxon (Mann-Whitney U) test

Hello everyone, I'm having some trouble interpreting the results of a Wilcoxon (Mann-Whitney U) test. Hope you can help. This is the R script that I am running: a <- c(1, 1, 1, 1, 1, 1, 1, 1, 3, 1, ...
 Filipe CorreiaOct 2, 2013 at 3:33 pmOct 5, 2013 at 11:19 am
• 10

#### [R] Lattice xyplot: Fill Legend Points

When I specify pch = 19 for a scatter plot the points are filled circles. Deapite reading ?points and trial-and-error experimentation I have not found how to have the legend symbols (now open ...
 Rich ShepardOct 17, 2013 at 3:17 pmOct 18, 2013 at 12:28 pm
• 9

#### [R] trying to compile R in win 7 (with Rtools)

hello all, I am trying to compile the R in Win7 and compiles one small part but the script don't move from the 'base' directory to 'stats' I installed the Rtools likee administrator and call the ...
 Cleber N.BorgesOct 5, 2013 at 12:03 amOct 6, 2013 at 2:45 pm
• 8

#### [R] add a color band

Hi all, I would like to ask your help to add a color band (Î™ am not sure regarding the right term, this color band at the right of the plot "describing" values with their corresponding color. For ...
 AlaiosOct 25, 2013 at 9:38 amNov 4, 2013 at 2:18 pm
• 8

#### [R] How to view un-sampled data from a randomly sampled dataset

Hi there- I have a 150 row dataset (data). I create "y" a randomly sampled (without replacement) set number of observations (40): y<-data[sample(1:nrow(data),40,replaceúLSE),] I would like to make a ...
 ErinuOct 23, 2013 at 6:13 pmOct 23, 2013 at 8:47 pm
• 8

#### [R] Is there something wrong with R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"?

Hi, pnorm(-1.53,0,1) under version 3.0.2 gives 0.05155075. I am pretty sure it should be 0.063. Is there something wrong with this version of R? I am using: R version 3.0.2 (2013-09-25) -- "Frisbee ...
 Tom soyerOct 16, 2013 at 2:54 pmOct 16, 2013 at 3:47 pm
• 8

#### [R] Transposing the output of 'table'

R 3.0.1 OS X Colleagues, If I execute the command: table(OBJECT) the output might look like: 1 2 25 336 I would like it to appear as: 1 25 2 336 I can accomplish this with: TABLE <- table(OBJECT) ...
 Dennis FisherOct 6, 2013 at 5:30 pmOct 7, 2013 at 10:11 pm
• 7

#### [R] data frame pointers?

Hello, I've been running several programs in the unix shell, and it's time to combine results from several different pipelines. I've been writing shell scripts with heavy use of awk and grep to make ...
 Jon BROct 23, 2013 at 11:36 pmOct 24, 2013 at 12:59 pm
• 7

#### [R] Gaussian Quadrature for arbitrary PDF

Hi all, We know that Hermite polynomial is for Gaussian, Laguerre polynomial for Exponential distribution, Legendre polynomial for uniform distribution, Jacobi polynomial for Beta distribution. Does ...
 Marino DavidOct 11, 2013 at 12:02 amOct 21, 2013 at 7:51 am
• 7

#### [R] saveXML() prefix argument

I'm using the "XML" package and specifically the saveXML() function but I can't get the "prefix" argument of saveXML() to work: library("XML") concepts <- c("one", "two", "three") info <- c("info ...
 Earl BrownOct 17, 2013 at 3:45 amOct 20, 2013 at 3:49 pm
• 7

#### [R] dmvnorm returns NaN

Greets, I'm using nlminb() to estimate the parameters of a multivariate normal random sample with missing values and ran into an unexpected result from my call to dmvnorm() within the likelihood ...
 Steven LeBlancOct 18, 2013 at 4:11 amOct 18, 2013 at 6:16 pm
• 7

#### [R] How to obtain restricted estimates from coxph()?

Hello, I'm trying to use coxph() function to fit a very simple Cox proportional hazards regression model (only one covariate) but the parameter space is restricted to an open set (0, 1). Can I still ...
 YOct 16, 2013 at 12:58 amOct 17, 2013 at 12:05 pm
• 7

#### [R] iconv question: SQL Server 2005 to R

A colleague is sending me quite a few files that have been saved with MS SQL Server 2005. I am using R 2.15.1 on Windows 7. I am trying to read in the files using standard techniques. Although the ...
 Ira SharenowOct 8, 2013 at 11:02 pmOct 11, 2013 at 2:27 pm
• 6

#### [R] time series has no or less than 2 periods

Hello, I have been tasked with taking an excel file that my colleague had implemented Triple Exponential Smoothing and recreate using R. The following image shows the before and after of smoothing ...
 Daniel HickmanOct 3, 2013 at 3:32 pmJan 6, 2014 at 5:42 pm
• 6

#### [R] Adding up normally distributed numbers seems to not create a t-distribution

Hi there, I have found a strange behavior in R that puzzles me - maybe it is a bug or a basic scientific misunderstanding of mine? anyway, I would highly appreciate some feedback on this, since I did ...
 Kramer, ChristianOct 25, 2013 at 2:48 pmOct 26, 2013 at 8:56 am
• 6

#### [R] R - How to "physically" Increase Speed

Hi, My name is Alexandre Khelifa and I have been using R at my work for about 2 years. I have been working on a project when we do Monte Carlo Simulation and it involves a lot of calculations. I am ...
 Alexandre KhelifaOct 21, 2013 at 11:12 pmOct 26, 2013 at 8:03 am
• 6

#### [R] speeding up a loop

Hey R professionals, I have a large dataset and I want to run a loop on it basically creating a new column which gathers information from another reference table. When I run the code, R just freezes ...
 Ye LinOct 17, 2013 at 9:56 pmOct 18, 2013 at 7:56 pm
• 6

#### [R] S4 base class

Greetings, I have an S4 class "B" (Base) which defines a function f=f(this="B",...) Dervided from?B we have a derived class D which also defines a function f=f(this="D",...) In the definition of D::f ...
 Michael MeyerOct 17, 2013 at 11:21 amOct 17, 2013 at 6:15 pm
• 6

#### [R] using ddply with segmented regression

Hello, Iâ€™m unsuccessfully trying to apply piecewise linear regression over each of 22 groups. The data structure of the reproducible toy dataset is below. Iâ€™m using the â€˜segmentedâ€™ package, ...
 Prew, PaulOct 12, 2013 at 3:13 amOct 17, 2013 at 12:16 am
• 6

#### [R] Small p from binomial probability function.

Hi, I got given some code that uses the R function pbionom: p <- mut * t sumprobs <- pbinom( N, B, p ) * 1000 Which gives the output of a probability as a percentage like 5, 50, 95. What the code ...
 Benjamin Ward (ENV)Oct 9, 2013 at 1:53 pmOct 16, 2013 at 10:15 pm
• 6

#### [R] using a variable for a column name in a formula

lm(height ~ ., data=X) works fine. However nnn <- "height" ; lm(nnn ~ . ,data=X) fails How do I write such a formula, which depends on the value of a string variable like nnn above? A typical ...
 David EpsteinOct 13, 2013 at 9:04 pmOct 14, 2013 at 7:41 am
• 6

#### [R] Using "cpquery" function from bnlearn package inside loop

Hi everyone, I'm attempting to use the bnlearn package to calculate conditional probabilities, and I'm running into a problem when the "cpquery" function is used within a loop. I've created an ...
 Ryan MorrisonOct 9, 2013 at 5:20 pmOct 11, 2013 at 8:25 pm
• 6

#### [R] Help required graphing factors with predicted model settings

Dear R wizards, Though I hate to do it after weeks of my code not working I need some help since I cant find an example which seems to work. I am trying to create a graph which show the probability ...
 Rebecca StirnemannOct 9, 2013 at 9:35 pmOct 11, 2013 at 12:31 pm
• 6

#### [R] Add function to each row excluding certain columns

Hello I've got a matrix of the following form BARN BCGE BCVN BEAN Restriction 1 Restriction 2 Restriction 3 Restriction 4 Restriction 5 alpha.1 0.000172449 7.87E-05 -0.003271044 0.000921609 9.28E-19 ...
 LaroOct 9, 2013 at 8:26 pmOct 9, 2013 at 11:01 pm
• 6

#### [R] select unique by multiple values

Hi, New to R here. Lots of fun. Still rather green though. I'd like to select unique items from a list that looks like this (for example): $x [1] 8 6 9 0 0 3 9 7 1 9$y [1] 1 2 9 5 1 2 0 9 2 9 \$z [1] ...
 Ronald PetersonOct 9, 2013 at 11:50 amOct 9, 2013 at 8:43 pm
• 6

#### [R] quote a column of a dataframe by its name

Dear All, I have a question, suppose X is a dataframe, with column names as "x1", "x2", "x3", ..... And I would like to use the i-th column by X[,'xi']. But it seems the single quote and double quote ...
 JieOct 4, 2013 at 4:06 pmOct 5, 2013 at 7:18 am
• 6

#### [R] storing element number of a list in a column data frame

#let's suppose I have a list like this mytest<-list(45, NULL, 18, NULL, 99) #to note that this is just an amended example because in fact #I'm dealing with a long list (more than 400 elements) #with ...
 Massimo BressanOct 3, 2013 at 2:41 pmOct 4, 2013 at 6:32 am
• 6

#### [R] glm's for a logistic regression - no warnings?

I have this weird data set with 2 predictors and one dependent variable - attached. predictor1 has all zeros except for one 1. I am runnning a simple logistic regression: temp<-read.csv("x data for ...
 Dimitri LiakhovitskiOct 1, 2013 at 2:41 pmOct 1, 2013 at 3:47 pm
• 5

#### [R] bug in dummy.coef?

Dear all, Running the following code produces an error in dummy.coef. I guess it might be a bug.. Error in rep.int(xl[[i]][1L], nl) : invalid 'times' value R version 3.0.1 (2013-05-16) Platform ...
 Alexandra KuznetsovaOct 24, 2013 at 8:51 amOct 25, 2013 at 8:34 pm
• 5

#### [R] How can I use a script "l" (LaTeX \ell) in mathematical annotation of plots?

Due to convention a script "l" - $$\ell$$ (LaTeX \ell) is used to represent a certain quantity in something I'm working on. I'm unable to figure out how to use it in R. It's not included in the list ...
 Byron DomOct 13, 2013 at 5:53 pmOct 25, 2013 at 10:40 am
• 5

#### [R] Scripting call to R-Studio compile PDF

Hey everyone, I have several RStudio (.rnw) files that I am using a script to assemble into a composite document. For this purpose, it would be helpful if the script could automatcially make a call ...
 Adam HughesOct 23, 2013 at 5:39 pmOct 24, 2013 at 6:28 am
• 5

#### [R] matrix of mean values

Dear all, I have a data set where I want to make a matrix of the mean values using 3rd column (value). Where rows are unique �loc� and columns would be �variables�. If there is one observation or no ...
 Nico MetOct 8, 2013 at 2:47 pmOct 23, 2013 at 12:58 pm
• 5

#### [R] How do I use simple calls to java methods?

I need to learn how to set up two methods (java functions) so I can call them from R. Currently I just copy and paste R code into the R console. A little piece of the R code inside a loop is: linTm ...
 HurrOct 22, 2013 at 12:31 amOct 23, 2013 at 4:23 am
• 5

#### [R] Loop for taking sum of rows based on proximity to other non-NA rows

Hi, May be this helps: dat1 <- structure(list(Position = c(15L, 22L, 38L, 49L, 55L, 61L, 62L, 14L, 29L, 63L, 46L, 22L, 18L, 24L, 22L, 49L, 42L, 38L, 29L, 22L, 29L, 23L, 42L), Count = c(15L, NA, NA, ...
 ArunOct 18, 2013 at 8:19 pmOct 21, 2013 at 3:21 am
• 5

#### [R] bold dot size and name in plot

Dear useRs, I have the following data "z" of two variables "x"(z[,1]) and "y"(z[,2]). structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, ...
 Eliza bottoOct 19, 2013 at 9:29 pmOct 20, 2013 at 9:26 pm
• 5

#### [R] loop not working my way

Dear R users, Suppose I want to randomly generate some data, in matrix form, randomly swap some of the elements and calculate trace of the matrix for each of these stages. If the value of trace ...
 LazOct 19, 2013 at 5:41 pmOct 20, 2013 at 4:54 pm
• 5

#### [R] bug(?) in str() with strict.width = "cut" when applied to dataframe with numeric component AND factor or character component with longerlevels/strings

Dear list subscribers, here is a small artificial example to demonstrate the problem that I encountered when looking at the structure of a (larger) data frame that comprised (among other components) ...
 Gerrit EichnerOct 15, 2013 at 11:53 amOct 16, 2013 at 9:44 am
• 5

#### [R] project parallel help

I'm running package parallel in R-3.0.2. Below are the execution times using system.time for when executing serially versus in parallel (with 2 cores) using parRapply. Serially: user system elapsed ...
 Jeffrey FlintOct 14, 2013 at 8:25 pmOct 15, 2013 at 7:05 pm
• 5

#### [R] Splitting times into groups based on a range of times

Hi all, I hope you can help with this one! I have a dataframe: 'df' that consists of a vector of times: 'dt2' and a vector of group id's: 'group': dates2=rep("01/02/13",times=8) ...
 Benjamin GillespieOct 10, 2013 at 10:35 pmOct 14, 2013 at 3:38 am
• 5

#### [R] Create sequential vector for values in another column

Hello all - I have an example column in a dataFrame id.name 123.45 123.45 123.45 123.45 234.56 234.56 234.56 234.56 234.56 234.56 234.56 345.67 345.67 345.67 456.78 456.78 456.78 456.78 456.78 456.78 ...
 Steven RanneyOct 11, 2013 at 1:26 pmOct 11, 2013 at 5:23 pm
• 5

#### [R] Looking for package to solve for exponent using newton's method

Hi, I'm looking for an R function/package that will let me solve problems of the type: 13 = 2^x + 3^x. The answer to this example is x = 2, but I'm looking for solutions when x isn't so easily ...
 Ken TakagiOct 10, 2013 at 6:39 pmOct 11, 2013 at 3:11 pm
• 5

#### [R] Convert a factor to a numeric

foo <- as.numeric(as.character(your_factors) ). It's a common mistake to forget the first conversion, in which case you end up with an integer sequence rather than the desired values. -- View this ...
 Carl WitthoftOct 10, 2013 at 11:41 amOct 10, 2013 at 2:00 pm
• 5

#### [R] Need help with plotting the graph

Hello All, The version of R I am using is as follows platform x86_64-pc-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 14.1 year 2011 month 12 day 22 svn rev 57956 ...
 Prasad JoshiOct 7, 2013 at 10:02 amOct 8, 2013 at 6:32 am