r/R_Programming • • Feb 29 '16

Interactive Heat Map of the United States

1 Upvotes

I was wondering, what was the best way to make an interactive heat map of the united states that has the ability to click on a state and have it link over to a more zoomed in version of that state at the county level. Thanks for the help!


r/R_Programming • • Feb 26 '16

Newbie trying to do science--not sure how to get the packages I need.

1 Upvotes

I'm running R 3.2.3, trying to get the packages "phyloseq" and "rncl", but both return an error saying they're not available for R 3.2.3. What can I do? I need these to run the unifrac analysis I need for my data, and my collaborator sent me a chunk of code where, right off the bat, those packages are part of the necessary libraries list:

library("phyloseq")    
library(rncl)
library("ggplot2")    
packageVersion("phyloseq")

I'm at a loss. What am I supposed to do if I need the packages and they aren't available?

> install.packages("phyloseq")
Installing package into ‘C:/Users/My.Name/Documents/R/win-library/3.2’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘phyloseq’ is not available (for R version 3.2.3)

r/R_Programming • • Feb 22 '16

Calculating max/min on a rolling subset of rows in a data frame

1 Upvotes

Hi all,

I have a data frame that looks like below. I'd like to calculate a rolling x period range of High-Low (for example, a rolling 4 week range). For example I'd like to get rows 1-4 and select max(High) and min(Low) on the subset. Then I'd like to do the same for rows 2-5, 3-6, etc. Any pointers on how I could accomplish?

thanks,

Joseph

tail(esdata, 10) Name Date.Time Open High Low Last Volume Open.Interest range 252 @ES# 12/18/2015 2001.50 2072.75 1983.25 1992.00 11081668 11615225 89.50 253 @ES# 12/25/2015 1997.25 2059.75 1995.25 2051.25 3749351 10106617 64.50 254 @ES# 1/1/2016 2051.25 2075.00 2030.25 2035.50 3279125 9965762 44.75 255 @ES# 1/8/2016 2037.75 2043.50 1910.00 1911.50 11806740 13001697 133.50 256 @ES# 1/15/2016 1909.25 1946.50 1849.25 1875.00 14306186 13838325 97.25 257 @ES# 1/22/2016 1869.75 1907.50 1804.25 1899.25 11562388 11401377 103.25 258 @ES# 1/29/2016 1899.50 1933.00 1851.25 1930.00 10194507 14381224 81.75 259 @ES# 2/5/2016 1929.75 1940.00 1865.00 1875.25 11274706 14713132 75.00 260 @ES# 2/12/2016 1876.25 1884.50 1802.50 1858.25 13048754 15018411 82.00 261 @ES# 2/19/2016 1865.25 1933.50 1865.00 1914.25 7096449 8963282 68.50


r/R_Programming • • Feb 18 '16

Slack community for data science

Thumbnail
experfylabs.typeform.com
1 Upvotes

r/R_Programming • • Feb 18 '16

As an R programmer, what is your preferred features you want to have in the IDE you're using?

1 Upvotes

r/R_Programming • • Feb 18 '16

Nusselt number correlation!!

1 Upvotes

Im working on a project that requires me to calculate the Nusselt number(heat transfer coefficient, ChemE related) and was wondering if theres a built in library to calculate an equation of form Nu = a * Rem * Prn, where a, m, n are constants and have to be calculated based on values provided for Re, Pr and Nu.


r/R_Programming • • Feb 16 '16

Sub on the whole object?

1 Upvotes

Is it possible to substitute "," to "." for a whole object? The "," makes values are stored as factors instead of numeric. I can use sub for a column, but if I use it on the whole object the results are confusing


r/R_Programming • • Feb 13 '16

Finished reading my first R programming book. Now What?

1 Upvotes

I have finished reading "R for Everyone: Advanced Analytics and Graphics". Based on what I learnt I am also making a small project where I am analyzing pharmacy data.

However I want to know what should I learn next in R. Should I start learning machine learning? or do you think something else will help me more.

Sorry for the vague question... i think it depends on person to person... but I needed some help in taking the right next step.


r/R_Programming • • Feb 11 '16

Maximizing MLE function(need help)

1 Upvotes

Hey guys, new o R programming. I have a likelihood function that I need to maximize in relation to parameter alpha, I have also the data of a set of experiments to use as input. All the data is already on R but IDK how to create a function nor to maximize it. Any help?

The function is: LL= ∑_in▒〖(Ln(〗 Pα(Nk/N)nk+(ln⁡(Pα(1-Nk/N)n-nk )


r/R_Programming • • Feb 09 '16

Formatting Dates Messes up Graph

1 Upvotes

When I input the below and then graph the dates, I get the dates in a form of "YYYY-MM-DD" and there is a gap, as should be, in the dates that is represented in the x-axis where no data exists for several months.

grocDates <- as.Date(grocExp[ , Date], origin = "1899-12-30")

However, I want the dates in a "MMM-YYYY" form so I format the dates using the below code. But, this removes the gap in the graph where data is missing and makes one continuous and misleading graph.

grocDates <- format.Date(grocDates, "%b-%Y")

Why is it doing this and how can I fix it?

Thanks for your assistance.


r/R_Programming • • Jan 31 '16

Library(textir) normalize?!

1 Upvotes

So I am brand new to R attempting to work my way through the book "Data Mining and Business Analytics with R". Page 120 <see below> has sample code that I am trying to run. The book says it requires the 'textir' library but when I attempt to run the 'normalize' command it gives me an error saying it doesn't recognize it. Anyone have any suggestions? Is there a library I am forgetting to load or maybe a known issue with 'textir'?

R Version: x64 3.2.3 RStudio: 0.99.491

******* Forensic Glass ******

library(textir) ## needed to standardize the data library(MASS) ## a library of example data sets data(fgl) ## loads the data into R; see help(fgl) fgl

data consists of 214 cases

here are illustrative box plots of the features

stratified by glass type

par(mfrow=c(3,3), mai=c(.3,.6,.1,.1)) plot(RI ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Al ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Na ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Mg ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Ba ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Si ~ type, data=fgl, col=c(grey(.2),2:6)) plot(K ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Ca ~ type, data=fgl, col=c(grey(.2),2:6)) plot(Fe ~ type, data=fgl, col=c(grey(.2),2:6))

n=length(fgl$type) nt=200 set.seed(1)

to make the calculations reproducible in repeated runs

train <- sample(1:n,nt) x <- normalize(fgl[,c(4,1)]) x[1:3,] library(class) nearest1 <- knn(train=x[train,],test=x[-train,], cl=fgl$type[train],k=1) nearest5 <- knn(train=x[train,],test=x[-train,],cl=fgl$type[train],k=5) data.frame(fgl$type[-train],nearest1,nearest5)

book url: http://www.nataraz.in/data/ebook/hadoop/Data_Mining_and_Business_Analytics_with_R__Johannes_Ledolter.pdf


r/R_Programming • • Jan 26 '16

Trouble with quantmod

1 Upvotes

I'm very much new to R. Posted this on Stackoverflow and still have not idea what's going on. was hoping some kind soul here could help me. I'm trying to download economic data through quantmod but I keep on getting an error that no one else seems to get. Here's the code:

library(quantmod) library(lubridate)

getSymbols("PAYEMS", src=("FRED"), return.class = "xts")

and here's the output:

Error in charToDate(x) : character string is not in a standard unambiguous format

Any clues?

Best,

James


r/R_Programming • • Jan 22 '16

Interactive Florida County Heat Maps

1 Upvotes

Hi,

I was just wondering if there was a way to produce an interactive Florida heat map by counties in R. I have tried googleVis, D3 and a couple other packages with no luck so far. Thanks for the help!


r/R_Programming • • Jan 15 '16

Problem with plot

1 Upvotes

I'm plotting numbers from 0.05 to 5000 in a logaritmic scale but, on the axis, numbers appears like 1000.00, 2000.00, 5000.00; how can I delete those superfluous zeros from my plot?


r/R_Programming • • Jan 15 '16

significant zeros on axis

1 Upvotes

Hi, I'm plotting some data and I want Y axis values with 2 decimal, and the second one equal to zero for every value, so I've written:

interval_y<-seq(0,2,by=0.2) interval_y<-format(round(interval_y, 2), nsmall = 2) [...] axis(side=2,at=interval_y) ...

inteval_y has 2 decimals with the last one 0, but on the plot there is only the first decimal, how can I have on Y axis 0.00, 0.20, 0.40 etc.?


r/R_Programming • • Dec 10 '15

Help with Coupon Collector's Problem

1 Upvotes

Hi, I'm struggling with a script in R to simulate the coupon collector's problem. Any help would be greatly appreciated!

Here's the exercise: Write a function coupon(n) for simulating the coupon collector’s problem. That is, let X be the number of draws required to obtain all n items when sampling with replacement. Use your function to simulate the mean and standard deviation of X for n = 10 and n = 52

And here's my script:

coupon <-function(n) {
  coupons <- 1:n # set of coupons
  collect <- numeric(n)
  nums <-0
  while (sum(collect)<n)
  {
    i <- sample(coupons,1)
    collect[i] <- 1
    nums <- nums + 1
  }
  nums
}
## Simulate the mean and variance 
trials <-10
simlist <- replicate(trials,coupon(n))
mean(simlist)
var(simlist)

Whenever I run it I get the errors:

> simlist <- replicate(trials,coupon(n))
Error in coupon(n) : object 'n' not found
> mean(simlist)
Error in mean(simlist) : object 'simlist' not found
> var(simlist)
Error in is.data.frame(x) : object 'simlist' not found

Can anyone help explain why this is happening/what I can do to fix this?


r/R_Programming • • Nov 28 '15

Bioinformatic and r Help

1 Upvotes

So I have an assignment that I need to do in R. I have a set of data that I need to do a complete analysis of but I don't know what exactly I should do with it and what i should look for. http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE74201 the data comes from this study and it is publicly distributed. IF someone can help me wiht what test I should do and the coding that be great. I have also uploaded the raw data so you can take a look at it as well. The link I sent should give you the details about each piece of data. The assignment is open ended and i can do any analyses I want but i don't know what would be valuable for me to do. If you download the csv file, you will find that there are 32 samples as advertised in the write-up. They are labelled H and C as in the samples listed on the website. There seem to be 2 types of cells for each of H and C C(1-8) and H(1-8) involve neural stem cells or NSC C(9-16) and H(9-16) involve induced pluripotent stem cells The ones label with H are Huntington Disease patients and the ones label with C are the control. We see that the diseases phenotype only is there at the Neural Stem Cell Stage (NSC) So to see that we are comparing the transcriptomic analysis of HD iPSCs and HD NSCs compared to isogenic controls using RNA-Seq . Gene Raw_C1 Raw_C2 Raw_C3 Raw_C4 Raw_C5 Raw_C6 Raw_C7 Raw_C8 Raw_C9 Raw_C10 1 ACTG1 113419 115727 100639 97065 101324 105197 112475 99720 50004 58281 2 ACTB 84151 88863 76511 73913 75466 79135 90264 77132 61924 71601 3 RPL3 52703 51904 48555 45395 47168 48988 46702 46256 36473 42333 4 GAPDH 58319 56809 49762 48065 50149 52756 52970 48144 55073 67575 5 GNAS 81324 84549 68604 67267 72992 74836 81110 69956 14520 16946 6 HMGA1 20103 20087 17884 17892 18534 19287 20865 17525 35709 43352 Raw_C11 Raw_C12 Raw_C13 Raw_C14 Raw_C15 Raw_C16 Raw_H1 Raw_H2 Raw_H3 Raw_H4 1 55528 71057 48612 53337 48577 60080 99112 111297 140926 114817 2 74410 88842 65799 69050 66635 79832 82695 89975 108990 89987 3 40663 52495 35869 38741 35944 42922 40699 46100 58926 47849 4 57294 76422 51522 57676 52659 64661 48004 51725 64874 56552 5 17013 21180 14997 15755 14492 18334 79657 90086 106687 86985 6 40829 52233 35202 37777 35021 43830 16730 18462 22430 19800 Raw_H5 Raw_H6 Raw_H7 Raw_H8 Raw_H9 Raw_H10 Raw_H11 Raw_H12 Raw_H13 Raw_H14 1 99884 117296 116319 101994 55495 57677 57166 55263 58168 58923 2 78771 93560 96170 82570 69753 71757 78932 76185 74597 75800 3 44844 50257 47031 40376 41201 45752 41384 41460 47378 48067 4 49632 57455 53449 49765 60703 67657 59462 59079 64690 70837 5 82729 97349 93286 80310 18179 18081 17900 18467 18625 18213 6 16628 20498 19827 17428 39853 45617 42853 43212 43781 44048 Raw_H15 Raw_H16 1 52363 53036 2 74163 73997 3 36334 36058 4 53721 54471 5 15674 16681 6 37244 37802 this is the data i have


r/R_Programming • • Nov 24 '15

Is it possible to load TDMS files into R?

1 Upvotes

Hi,

Title says it all, I would like to import some raw streaming data in .TDMS format if possible, does anyone know of a package I can use?

Many Thanks


r/R_Programming • • Nov 17 '15

R studio crashes everytime I want to create a project?

1 Upvotes

Anybody else experienced this and know what to do?


r/R_Programming • • Nov 17 '15

Just trying to get through vitcap2 on ISwR

1 Upvotes

So as title says, I have package ISwR. I need to create a vector of age and a separate one of vital capacity. Simple enough, right?

But I can't even pull up the datafield/matrix and so I have no idea what my data are. I managed to pull up the plot but that's it...I'm so lost. Help please? (To be fair, I just started today. For an intro stats class.)


r/R_Programming • • Nov 15 '15

What is the difference between as.factor() and factor()?

1 Upvotes

Sorry, I am very new to R.


r/R_Programming • • Nov 14 '15

Question on merging data frames

1 Upvotes

Hi, I hope this is an appropriate question for here!

I'm quite new to R and need help merging two data frames.

The two data frames are similar in number of rows (around 10,000) and share one common column (species_name), which for the most part has the same species within it.

Essentially I want to match up the data frames via way of the matching species names (there will be a few that don't have a match and I'm happy to lose these if necessary) so the information in the other columns is all in one data frame.

I hope this makes sense and thanks in advance!


r/R_Programming • • Nov 04 '15

Quick R Assignment Help

1 Upvotes

Hello reddit. I have a question pertaining to my data frame. The code is as follows:

check <- function(x) {
 subj <- unique(data$participants[data$participants == x])
 numSessions <- length(unique(data$sessions[data$participants == x]))

 if (numSessions > 1) {
  sessionIDs <- data$sessions[data$participants == x]
  cat(x, "has", numSessions, "sessions:\n")

  for (id in unique(sessionIDs)) {
   cat("Exclude session", id, "\n")
  }
}
}

data <- data.frame(participants = c('a101', 'a101', 'a101', 'a101', 'a101', 'b102', 'b102', 'b102', 'b102', 'b102', 'c103', 'c103', 'c103', 'c103', 'c103'), sessions = c(32651, 32652, 32652, 32652, 32653, 44444, 44444, 44444, 44444, 44444, 36543, 36543, 36543, 36543, 36543))
for (participant in (unique(data$participants))) {
check(participant) 
}

In my function that I call "check", if there are multiple sessions per participant ID, I want to exclude the extra sessions. For example, participant a101 has three separate sessions. I want to have my code output something along the lines of: exclude session 32652 exclude session 32653. Is there a way to use the cat function to have it "skip" over the first session number and only list the other two instead?


r/R_Programming • • Oct 30 '15

HELP with survey "Study on determinants of R programming Acceptance"

1 Upvotes

I am conducting a research study on R programming Acceptance. The results from this survey will help better understand the future use of 'R’. This survey should take 4-5 minutes to complete. Be assure your responses will be strictly confidential. Thanks for agreeing to take part in this study. http://goo.gl/forms/X2aiBTzxHw


r/R_Programming • • Sep 23 '15

"variable-sized object may not be initialized" error when sourcing a cpp file

1 Upvotes

I am trying to sourceCpp this file:

#include <SDKDDKVer.h>
#include <windows.h>
#include <tlhelp32.h>
#include <tchar.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <Rcpp.h>

using namespace Rcpp;

typedef const char* LPCTSTR; 
typedef const void* LPCVOID;
typedef unsigned long DWORD;

// [[Rcpp::export]]
void append(LPCTSTR filename, LPCVOID buf, DWORD writeSize) {
	LARGE_INTEGER size;
	size.QuadPart = 0;
	HANDLE fh = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		std::ostringstream error;
		error << "Failed to created file: " << filename << "\nError: " << GetLastError();
		throw error.str();
	}
	GetFileSizeEx(fh, &size);
	SetFilePointerEx(fh, size, NULL, FILE_BEGIN);
	if (WriteFile(fh, buf, writeSize, NULL, NULL) == 0) {
		std::ostringstream error;
		error << "Failed to write file: " << filename << "\nError: " << GetLastError();
		throw error.str();
	}
	CloseHandle(fh);
}

// [[Rcpp::export]]
std::string readTail(LPCTSTR filename,  DWORD readSize) {
	char buf[readSize] = { 0 };
	LARGE_INTEGER size;
	size.QuadPart = 0;
	HANDLE fh = CreateFile(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		std::ostringstream error;
		error << "Failed to created file: " << filename << "\nError: " << GetLastError();
		throw error.str();
	}
	GetFileSizeEx(fh, &size);
	size.QuadPart -= readSize;
	SetFilePointerEx(fh, size, NULL, FILE_BEGIN);
	if (ReadFile(fh, buf, readSize, NULL, NULL) == 0) {
		std::ostringstream error;
		error << "Failed to read file: " << filename << "\nError: " << GetLastError();
		throw error.str();
	}
	CloseHandle(fh);
	std::string s(buf);
}

// [[Rcpp::export]]
void truncateTail(LPCTSTR filename, long truncateSize) {
	LARGE_INTEGER size;
	size.QuadPart = 0;
	HANDLE fh = CreateFile(filename, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		std::ostringstream error;
		error << "Failed to created file: " << filename << "\nError: " << GetLastError();
		throw error.str();
	}
	GetFileSizeEx(fh, &size);
	size.QuadPart -= truncateSize;
	SetFilePointerEx(fh, size, NULL, FILE_BEGIN);
	if (SetEndOfFile(fh) == 0) {
		std::ostringstream error;
		error << "Failed to set end of file: " << filename << "\nError: " << GetLastError();
		throw error.str();
	}
	CloseHandle(fh);
}

And I get the following error:

g++ -m64 -I"C:/PROGRA~1/R/R-32~1.2/include" -DNDEBUG     -I"C:/rlib/Rcpp/include" -I"C:/kaiyin"  -I"d:/RCompile/r-compiling/local/local320/include"     -O2 -Wall  -mtune=core2 -c truncateTail.cpp -o truncateTail.o
In file included from C:/PROGRA~1/R/R-32~1.2/include/R.h:50:0,
                 from C:/rlib/Rcpp/include/Rcpp/r/headers.h:52,
                 from C:/rlib/Rcpp/include/RcppCommon.h:29,
                 from C:/rlib/Rcpp/include/Rcpp.h:27,
                 from truncateTail.cpp:9:
C:/PROGRA~1/R/R-32~1.2/include/R_ext/RS.h:45:0: warning: "ERROR" redefined [enabled by default]
c:\rtools\gcc-4.6.3\bin\../lib/gcc/i686-w64-mingw32/4.6.3/../../../../i686-w64-mingw32/include/wingdi.h:70:0: note: this is the location of the previous definition
truncateTail.cpp: In function 'std::string readTail(const char*, DWORD)':
truncateTail.cpp:39:27: error: variable-sized object 'buf' may not be initialized
make: *** [truncateTail.o] Error 1
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-32~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-32~1.2/share/make/winshlib.mk" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="sourceCpp_6.dll" WIN=64 TCLBIN=64 OBJECTS="truncateTail.o"' had status 2 
Error in sourceCpp("C:/kaiyin/truncateTail.cpp") : 
  Error 1 occurred building shared library.

What went wrong here?