Questions tagged [r]

R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible examples others can run using copy & paste. Show desired output entirely. Use dput() for data & specify all non-base packages with library(). Don't embed pictures for data or code, use indented code blocks instead. For statistics questions, use https://stats.stackexchange.com.

r
Filter by
Sorted by
Tagged with
1 vote
0 answers
557 views

How to obtain subset of combinations only - combinations with restrictions

I will explain my problem in two different ways, please pick the one you understand better. If something's unclear please, tell me in the comments. Version 1 For the sake of trying to make it ...
dmeu's user avatar
  • 3,972
2 votes
0 answers
351 views

R LiblineaR weights do not change with class labels

I want to use the LiblineaR library in R which is efficient for large datasets. (I want to use the l1-norm on wieghts for feature selection but not relevant for this question). What I observed is that ...
Krrr's user avatar
  • 462
4 votes
3 answers
12k views

data.table group by with a filter condition [duplicate]

Given a data.table like the one below, I would like to create a new column which is the value summed by region, and where period == 0. region period value 1: US 0 10 2: US 1 ...
Abiel's user avatar
  • 5,351
-2 votes
2 answers
547 views

how can I put two bar charts to one graph?

I use two variables from a dataset: I got the graph for one of them: barchart(data_derm$PP_SD_ARBVLZ=="1") I want to put the graph for this variable data_derm$PP_SD_ARBTLZ=="1" next to the other ...
user2373707's user avatar
1 vote
2 answers
4k views

Can't remove legend in scatterplot

Here is my code scatterplot(LitterMass~WormMass | Site, reg.line=FALSE, smooth=FALSE, spread=FALSE, id.method='mahal', id.n = 2, boxplots=FALSE, span=0.5, by.groups=...
user2999583's user avatar
1 vote
4 answers
1k views

How to run R with F5 key in vim?

I have installed vim and R in xp ,how to write map command in _vimrc? I have written some of the command such as map <F5> :w<CR>:!R,when i press F5,can i make R script run? I edit a ...
showkey's user avatar
  • 510
0 votes
1 answer
1k views

Library for interactive time series charting

For my recent project I am looking to build a software capable of visualizing financial charts in a dynamically and interactive matter. The workflow is as follows: I gather data from my data provider ...
user1356695's user avatar
0 votes
1 answer
6k views

how to Ignore some values in column of data.frame

I'm new with programming and try to work with R for the first time. I'm actually trying to set some points into a plot and fail to do the easiest things... First of all: How can i use a function like:...
user2999399's user avatar
0 votes
2 answers
204 views

Fill missing values from bottom to up

Example of problem date X Y 2012-07-05 00:01:19 0.0122 NA 2012-07-05 03:19:34 0.0121 NA 2012-07-05 03:19:56 0.0121 0.027 2012-07-05 03:20:31 0.0121 ...
foc's user avatar
  • 977
0 votes
1 answer
1k views

lapply to multiple arguments in a function

I am using the lapply function in the following form: y=rnorm(10) x1=c(1,1,1,2,2,2,3,3,3,4) x2=c(5,5,6,6,7,7,8,8,9,9) x3=c(7,7,8,8,9,9,10,10,11,11) t1 <- outer(x1, unique(x1), '<=') t2 <- ...
user17645's user avatar
2 votes
1 answer
224 views

RPy boolean values for texreg

I'm using the texreg package to print LaTeX tables for my R linear models. The default settings of the package include printing many things which are irrelevant for my analysis. Luckily the package ...
TheChymera's user avatar
  • 17.5k
0 votes
4 answers
534 views

R :histogram of 100 exponential numbers with mean=10 & do the same thing 50 times

(a) I have to make a histogram of 100 exponential numbers with mean=10 and estimate the median (b)again I have to do the same thing 50 times as (a) and find a vector exp such that exp <- ...
user2983722's user avatar
1 vote
1 answer
1k views

Efficient random array of probability weights that sum 1

I need something very simple and it seems to me that my solution has too many steps (considering that R is done for statistics): All I need is an array of N probability weights (between 0 and 1) that ...
dmeu's user avatar
  • 3,972
9 votes
1 answer
14k views

Using NNET for classification

I am new to neural networks and I have a question about classification with the nnet package. I have data which is a mixture of numeric and categoric variables. I wanted to make a win lose prediction ...
Kharoof's user avatar
  • 597
-2 votes
1 answer
250 views

Yahoo search button name in html

I wanted to get the html of search yahoo search result using R code like below. If its google it would be like siteHTML<-getForm("google.com/search",hl="en",q="keyword",btnG="Search") In case of ...
user1639961's user avatar
3 votes
1 answer
396 views

How can I use ggplot2 and stat_bin to make a bar chart that includes numeric levels with no observations

I have data as an ordered factor, with levels 1,2,3,4,5. (This is Likert scale data.) I would like to use ggplot to create a bar chart of counts, but this must include all the levels, even the ones ...
GTK's user avatar
  • 133
0 votes
1 answer
103 views

R: rename hierarchy levels of an hts object

How can I rename the levels an hts (hierarchical and grouped time series) object created with the hts package? Example: abc <- ts(5 + matrix(sort(rnorm(200)), ncol = 4, nrow = 100)) x <- hts(...
user2030503's user avatar
  • 3,074
6 votes
2 answers
1k views

Why does scale produce a matrix?

scale seems like a useful function with the exception that it produces a matrix from a numeric vector like so: class(scale(mtcars$drat)) # [1] "matrix" Is there a function that produces a numeric ...
luciano's user avatar
  • 13.4k
10 votes
2 answers
90k views

R :Plot and save in a pdf file

Write R code to draw sample of size 100 from N(0,1) and N(5,1) each . Plot the two figures on the same graph.Save the graph as Sample.pdf in the working directory I. My attempt : pdf("SampleGraph....
user2983722's user avatar
6 votes
1 answer
574 views

animation in knitr document with ggplot figures

I am trying to use the following chunk in my knitr document that creates a pdf <<animate_gg,fig.show='animate', eval=TRUE>>= gg.list<-list() for (w.it in w.vals){ sub.final.pts.lf....
statistician_in_training's user avatar
1 vote
1 answer
304 views

how to insert .csv data in oracle table

here we can read the data with the read.csv function in R > mydata = read.csv("mydata.csv") > mydata Col1 Col2 Col3 1 100 a1 b1 2 200 a2 b2 3 ...
pop's user avatar
  • 11
4 votes
1 answer
2k views

R Roxygen link to parent function

Consider a base package XYZ, written by someone else, which has a function ABC, I want to extend the functionality of ABC in my new (NOT XYZ) package via the following method. ABC <- function(...){...
Nicholas Hamilton's user avatar
3 votes
1 answer
750 views

can't put Unix-style line-endings when using write.table under Windows

Here's some primitive code for an example: mydf <- data.frame(letters[1:10]) write.table(mydf, "out1r", eol="\r") write.table(mydf, "out1x0D", eol=rawToChar(as.raw(13L))) write.table(mydf, "...
Vasily A's user avatar
  • 8,546
3 votes
2 answers
135 views

How do I get in R the name of currently executed script when called via `r BATCH script file`

I call a script from a shell command line with r CMD BATCH myscript.R What do I have to do in myscript.R to get a character vector with the name of the script (i.e. "myscript.R")? Note: I found ...
halloleo's user avatar
  • 9,692
1 vote
1 answer
1k views

Selecting different numbers of columns on each row of a data frame

This question is about selecting a different number of columns on every row of a data frame. I have a data frame: df = data.frame( START=sample(1:2, 10, repace=T), END=sample(2:4, 10, replace=T),...
user2998362's user avatar
2 votes
1 answer
141 views

ggplot2 Create a new theme element outside of .elements_tree

I need to create a new theme element for ggplot2 How can I add a NEW item to the .elements_tree data structure (for reference, it starts at line 263 HERE) For instance, I have a particular situation ...
Nicholas Hamilton's user avatar
1 vote
1 answer
2k views

Random stratified sample from each factor levels

I have data set with two factors: Environments (4 levels), Individuals (500 in each environment) and response variable YD. As part of my analysis I have to randomly sample 100 individuals from each ...
hema's user avatar
  • 735
2 votes
1 answer
4k views

R - Perform Melt on Each Data Frame in a List

I have a several data files in a directory (all tsvs). One data file will look like this: Killed Rick Darryl Herschel Tyrese Shane Zombies 200 300 20 4 100 ...
sempervent's user avatar
0 votes
0 answers
112 views

R: call to lapply w/ nearest neighbors library yields error

Setting it up: library(kknn) event <- c('first', 'second', 'third', 'second', 'second', 'third', 'third', 'first') speed <- c(1.25, 2.22, 3.02, 4.22, 1.56, 2.77, 3.21, 1.55) time <- c(667, ...
Wells's user avatar
  • 10.6k
3 votes
1 answer
7k views

Label selected percentage values inside stacked bar plot (ggplot2)

I want to put labels of the percentages on my stacked bar plot. However, I only want to label the largest 3 percentages for each bar. I went through a lot of helpful posts on SO (for example: 1, 2, 3),...
Vivian's user avatar
  • 33
0 votes
1 answer
3k views

change legend symbols from boxplot in ggplot2

I am plotting a series of boxplots as well as points on top but my color legend shows all the symbols as little boxes. I've tried using override.aes but the problem persists. Bonus points if you can ...
Dominik's user avatar
  • 782
2 votes
1 answer
601 views

Using vectors instead of for loop in R

I have a long line of code and am trying to speed things up by removing for loops. As I under stand when you have multiple nested loops it can slow your code down. My original code contained 3 loops ...
CCurtis's user avatar
  • 1,818
2 votes
3 answers
623 views

sortable HTML output from R with images

I have some data in a data frame. There is a small image associated with each row. I'd like to be able to write this data to HTML along with the image and have it show up in each row as a thumbnail. ...
topepo's user avatar
  • 14k
5 votes
1 answer
9k views

writing multiple dataframe into one excel sheet using xlsx and R

I have a set of csv files in different directories, I would like to put them all in one excel file, each table in one excel sheet. I am using R and xlsx package. # loading the library library(xlsx) ...
Areza's user avatar
  • 5,881
0 votes
2 answers
2k views

PLS coefficients with r

I'm making a PLS model using packages "pls" and "ChemometricswithR". I'm able to perform the model but I have a problem. I did a leave-one-out validation and if I ask for the coefficients I can see ...
user2997766's user avatar
1 vote
1 answer
269 views

Sorting data on x-axis taking one variable as reference

Hello I think that this must be something stupid, but I am stuck.. I have 5 participants and two task participant<-1:5 scoreA<- c(20, 18, 19, 15,16) scoreB<- c(4, 2, 6, 1,3) I create a ...
ajestudillo's user avatar
10 votes
2 answers
1k views

Knitr: redirect chunk code output to terminal

I want to monitor some pretty lengthy parallelized computations embedded in a knitr file. The computations rely on a package I have written, and the relevant function uses mclapply from the multicore ...
Pepin_the_sleepy's user avatar
1 vote
1 answer
865 views

Extract columns with values matching a specific pattern

I have a multi-column GTF file, where each row has different number of columns: chr1 Cufflinks exon 12659 12721 . + . gene_id "XLOC_000001"; transcript_id "TCONS_00000001"; ...
Komal Rathi's user avatar
  • 4,214
1 vote
1 answer
6k views

Drawdowns- Performance Analytics error--- Factor and Numeric

Some data in a text file: date,p 2013-11-14,0.001 2013-11-13,-0.005 2013-11-12,0.001 library(PerformanceAnalytics) stuff<-read.csv("C:stuffexample.txt") str(stuff) 'data.frame': 3 obs. of 2 ...
Rhodo's user avatar
  • 1,274
4 votes
1 answer
1k views

R constructing sparse Matrix

I'm reading through instructions of Matrix package in R. But I couldn't understand the p argument in function: sparseMatrix(i = ep, j = ep, p, x, dims, dimnames, symmetric = FALSE, index1 = ...
GorillaInR's user avatar
2 votes
2 answers
99 views

How do I create two vectors from an existing vector (of characters) in R?

so I just started using R and I have to struggle every now and then. I have this vector of stimuli names such as: 1. abc1.jpg 2. abc2.jpg 3. bcd1.jpg 4. bcd2.jpg 5. cde1.jpg 6. cde2.jpg now the ...
roscoe1895's user avatar
2 votes
1 answer
181 views

Wrapping markdownToHTML input in an HTML container?

Does anyone know if it is possible have the output of knit2html (i.e. markdownToHTML) wrapped in an HTML container? Currently, everything gets dumped into <body>, which does not provide a lot ...
Keith Hughitt's user avatar
2 votes
1 answer
144 views

R data table usage as parameter in package

I have a problem using a data.table as a parameter to a function. If I define the function in the script I'm working in it works - see fn_good. If I define the function (identically) as part of a ...
Jeremy Affolter's user avatar
4 votes
2 answers
1k views

normalize ggplot histogram so that first height is 1 (to show growth) in R

I was wondering if there is a way to normalize the heights of the histograms with multiple groups so that their first heights are all = 1. For instance: results <- rep(c(1,1,2,2,2,3,1,1,1,3,4,4,2,...
conorfrailey's user avatar
0 votes
1 answer
3k views

Adding an arrow and marker on a map in R

I have made a map using ggplot2 package of R and also a geom_path visualized on it. Now, I want to add a few markers and just one arrow in order to show the direction of the path. For arrows there is ...
ArmMiner's user avatar
  • 215
5 votes
1 answer
3k views

How to use simultaneously superscript and variable in a axis label with ggplot2

I would like to use together a variable (here the vector element "type") and a unit containing a superscript (here m^2) inside n axis label. data <- list(houses = data.frame(surface = c(450, 320, ...
fstevens's user avatar
  • 1,297
-2 votes
1 answer
3k views

How to read a part of excel file into data frame r?

I need to read many .xlsx format files into data frame. Every excel file has the same format like Date GrossProfit NetProfit PnlLow 10/15/2013 3000 2500 -500 10/20/2013 3100 ...
Everest's user avatar
  • 21
2 votes
1 answer
1k views

Importing data associated with a given CAS number from the NIST webbook web site into R

I would like to retrieve information associated with a given CAS registry number (Chemical Abstracts Service nr) from the NIST webbook web site in R, using the provided API. E.g. for cas nr. "19431-...
Tom Wenseleers's user avatar
1 vote
0 answers
397 views

plot.ksvm invert x and y axis

here is my code, the plot a obtain is OK for the region drawn by the plot function, but not for the data. the axis are OK except for the data plotted by the plot.ksvm: x and y axis are inverted. why? ...
Manu H's user avatar
  • 543
1 vote
1 answer
165 views

faoutlier analysis takes too long

I'm doing an outlier analysis using forward.search in the faoutlier package in R, but it takes too long without any result. I just wanted to check whether I am doing it right, and how could I make the ...
Ehsan88's user avatar
  • 3,653