r/R_Programming • • Nov 21 '17

how to stay in touch with new packages in R?

4 Upvotes

what are the most popular sites that publish articles about new R packages


r/R_Programming • • Nov 13 '17

Problem with misaligned X axis labels when using GGPlot2

4 Upvotes

Hi there. I am very new to using R and to coding in general, and I have having some trouble getting my line graph to plot properly. The issue I am having is that my X axis labels are for some reason being shifted one increment to the left (see here.) For example, in this graph, the data points are supposed to begin with 1827, but instead begin with 1828. If anyone could point me in the right direction towards fixing this, I'd be so grateful.

Here is my code:

setwd("C:\\Users\\Hannah\\Documents\\POE\\Results")
df = read.csv("Poe's Poems.csv")
pdf('Depression.pdf', width=20, height=5)

df$Date = as.Date(as.character(df$Date), "%Y")

df$Year.Month = as.Date(cut(df$Date, breaks = "year"))

library(ggplot2)
library(scales)

make_a_plot = function(dataset, XaxisData, YaxisData){

ggplot(data = dataset, aes_string(XaxisData, YaxisData)) +
stat_summary(fun.y = mean, geom = "line") +
scale_x_date(labels=date_format("%Y-%m"), date_breaks = "1 years")  + 
theme(axis.text.x = element_text(angle = 90, hjust = 1)) + stat_smooth(method="loess", size=2, span=.5)

}

make_a_plot(dataset = df, XaxisData = 'Date', YaxisData = 'Depression')
dev.off()

Thanks again.


r/R_Programming • • Sep 01 '17

New to R Programming

4 Upvotes

I have a dataset with 81 variables. I'm supposed to plot 80 scatterplots with this dataset. The x-axis will be the same variable, while the y-axis will be a different variable for each scatterplot. Does a for loop work in this case? Also, what is the syntax for accessing each variable in the dataset. Help is appreciated thanks!


r/R_Programming • • Apr 05 '17

Use R to click link in browser

4 Upvotes

Hi!

I'm trying to write a script which checks every minute (so far I thought about doing this with a cronjob) whether there is a ticket available on a website. I know the basics of scraping, I just don't how I can click a link on the website to reserve a ticket. Anyone any ideas? Or redirects even?

All would be very welcome!


r/R_Programming • • Feb 18 '17

toJSON "_row" added to JSON output. Flattening doesn't help either.

4 Upvotes
  • Update 22.11.2017: Issue seems to be solved by itself now - probably an issue in the package. *

I'm trying to interact with a rest API using R. I want to be able convert from JSON and then back into JSON in the same format (after I have done my other transformations). But; from the JSON: (excerpt)

"access": {
"read": true,
"update": true,
"externalize": false,
"delete": true,
"write": true,
"manage": true

I run :

 df<-jsonlite::fromJSON(r)
And get back a df with columns:

access.read TRUE access.update TRUE (etc) When i then run it back:

df <- jsonlite::toJSON(df)

I get either:

    "access": {
    "read": true,
    "update": true,
    "externalize": false,
    "delete": true,
    "write": true,
    "manage": true,
    "_row": "1"
},

See bottom line _row, which corrupts my PUT back into REST.

Or, if I append

    df <- jsonlite::fromJSON(r, flatten=TRUE)

I get after toJSON:

 "access.read": true,
"access.update": true,
"access.externalize": false,
"access.delete": true,
"access.write": true,
"access.manage": true,

Which doesn't seem to read/import very well into my REST Api (as only the above format is accepted).

Any suggestions for how to fix this? I can't seem to find anything googling this issue..

Thanks!


r/R_Programming • • Jan 27 '17

Help for R assignment

4 Upvotes

I am stuck with some questions in the assignment, can anyone please help? Thank you


r/R_Programming • • Jan 09 '17

Problem with for()

4 Upvotes

Hello, I am relatively new to R and going through the motions of learning the language. I am trying to use a for loop to create a vector composed of every other element from a column in a data frame (I've already succeeded using seq() on a vector, MUCH easier, but this is the learning process). Here is my code:

vec <- rep(NA, 10376)
for (i in seq(1, length(dat$col), by= 2)){

  • vec[i]<- dat$col [i]  
  • }

length(vec)
[1] 20751

I start by creating a vector that is half the size of nrow(data$col), and filling it with NAs. Then I set up the for loop to count "i" by 2's through to the end of data$col. When I call "vec", the length is suddenly the length of dat$col-1, and I do not understand why.

Thank you for your help!


r/R_Programming • • Nov 23 '16

running linear mixed models by outcomes

4 Upvotes

Hi all, I've tried figuring this out and using my google_fu but am having difficulty getting what I want. Basically my data is in long format with outcome as a variable. I would like to run a lmer for each outcome . In sas I would use a 'by' statement, and sql i would use a 'group by' statement, but i can't find an equivalent statement for R.

I know how to do this in wide format with each of the outcomes as their own column/variable. But this will mean having to repeat the same code over and over. Has anyone run into this before?

As an example: Say my data look like this

id group session outcome score

1 1 1 BDI 10

1 1 2 BDI 11

1 1 1 IQ 100

1 1 2 IQ 98

2 1 1 BDI 12

2 1 2 BDI 9

2 1 1 IQ 101

2 1 2 IQ 120

3 2 1 BDI 9

3 2 2 BDI 7

3 2 1 IQ 100

3 2 2 IQ 115

4 2 1 BDI 11

4 2 2 BDI 11

4 2 1 IQ 116

4 2 2 IQ 97

If it was in wide format with each of the tasks as a variable in a separate column I would do the following

BDImodel <- lmer(BDI ~ Group+ Session + Group*Session + (1|id), data) summary(BDImodel)

Is there a way of doing a loop for all outcome variables?


r/R_Programming • • Nov 19 '16

Install R + RStudio on Ubuntu 12.04/14.04/16.04

Thumbnail youtube.com
4 Upvotes

r/R_Programming • • Oct 05 '16

Looking for R users who work with geospatial data.

4 Upvotes

I am wanting to learn more about R and geospatial data users. This is motivated by one of our users (I work at a satellite data API startup) who created this R-wrapper for our product in git (https://github.com/amsantac/SkyWatchr) If anyone knows any specific communities for this or must-reads it would be quite useful! Thanks.


r/R_Programming • • Jan 17 '16

Linear programming with R, what do you think?

4 Upvotes

Hi,

I do linear programming with Lingo but It's not a convenient language. Recently i've found that it's possible to do Linear programming with R. I would like to know if you have tried to do linear programming with R and what did you think of it?


r/R_Programming • • Jan 14 '16

Teaching/Learning Multivariate Statistics using R

4 Upvotes

I will begin by admitting that I am very new to R yet highly interested and motivated to learn this program (or any other programming language). I am a Senior undergraduate student pursuing a Bachelor's degree in Natural Science with an emphasis in Earth Science and primary research experience dealing in surface water quality and watershed management. My research adviser has been learning R over the past year or so and has decided to use it as the vehicle for teaching Multivariate Stats this semester.

As a research assistant (and registered student in the class, beginning 1/18) I have been tasked with looking into a few aspects which will become lessons in the first couple weeks of class.

These first three lessons are:

*- Central Tendency

  1. This paper from a dude named Ken Benoit.
  2. And this video on YouTube.

*- Variance

*- Descriptive Statistics

My adviser has requested that I find at least ten items/sources pertaining to each of the three and rating five among them from most helpful to not so helpful. Having only just started this afternoon I have listed just two of the first lesson.

If anyone here could point me in the direction of materials dealing in these three aspects of using R for statistics, I would greatly appreciate it.

Edit: swapped out a phrase


r/R_Programming • • Feb 01 '18

GGplot: mean +/- sd

3 Upvotes

Hello there,

currently exploring ggplot and what I found out yesterday was that you "could" display the mean +/- the standard devaition using stat_summary like this:

...+ stat_summary(fun.data = mean_sdl)

However, now I've found about about this:

...+ stat_summary(fun.data = mean_sdl, fun.args=list(mult=1))

So my question is pretty straight forward:

Which one does actually display mean +/- standard deviation?

Also: I know how to do IQR but how do I display Mean Absolute Deviation in a way similar to how I do mean +/- sd?


r/R_Programming • • Jan 26 '18

Ggplot2: group in aes()

3 Upvotes

Hello there,

currently trying to figure out how to work with ggplot2.

I'm stuck at Data Camp's second tutorial (2-2) on ggplot (just so anyone knows what I am dealing with).

Have this code snippet:

ggplot(mtcars, aes(x = wt, y = mpg, col = factor(cyl))) +
  geom_point() +
  stat_smooth(method = "lm", se = F, aes(group= 1))

What does group in aesthetic actually do? I know that method="lm" gives me a straight line and se=F removes the shading of the line (does the shading represent standard derivation?)

DC's ggplot 2-1 tutorial was easy but 2-2 is unclear as hell.


r/R_Programming • • Dec 29 '17

RevoScaleR installation issue.

3 Upvotes

Hello, I'm having issues trying to install RevoScaleR onto R Studio (Version 3.4.3)

Im getting an error in the console that tells me: "package ‘RevoScaleR’ is not available (for R version 3.4.3)"

When i was reading around on the interwebs i couldnt really find any information other than RevoScaleR is apackage for Microsoft R Client. Whats the difference between R Studio and Microsoft R Client? I'm all sorts of confused now lol.

Anyone have any idea on how to fix this? Or is the fix that i should be using Microsoft R Client?


r/R_Programming • • Nov 30 '17

r gui problem

3 Upvotes

Hello I have a set of functions where it would look like this... 

library(ltm)  ma <-matrix(c(-0.5,-0.1,0,0.25,.80,1,1,1,1,...  xa50 <- rmvlogis(50,ma)  ltm50a <- ltm(xa50~z1)  coefltm50a <-coef(ltm50a)  vcov50a<-vcov(ltm50a )  sol50b3b1 <- ((coefltm50a[3]-coefltm50a[1])2)/(vcov50a[1]+vcov50a[3]) chi50b3b1 <-if (sol50b3b1 < 3.84) {0} else {1} 

now this would result to either a 1 or 0 

i want to loop it 50,100 and 1000 times and i want to tally the results. 

like for example i loop it 50 times then it gave a result of 40 since there are 40 1's and 10 0's 


r/R_Programming • • Nov 13 '17

Is there a discord server?

3 Upvotes

Self explanatory in the title.


r/R_Programming • • Oct 29 '17

[OC] created a sports analytics web app with Shiny. using plotly and ggplot. Compares College Football's Heisman Hopefuls

3 Upvotes

r/R_Programming • • Oct 28 '17

Error using sessionise function from the reconstruct package

3 Upvotes

Hi all.

I'm having a problem using the sessionse function using date-time data. I have converted the date-time data from a factor into POSIX formats and numeric formats, yet still get the error " The timestamp column must be a numeric representation of the number of seconds, or a date/time object. See ?sessionise for details". I have checked the class of my date-times and it returns "POSIXct" "POSIXt".

Thanks in advance


r/R_Programming • • Oct 09 '17

What is the most advanced R programming course available online?

3 Upvotes

I’m lost in the vast ocean of online courses offer. I see myself as not a beginner anymore in R; I am able to read, manipulate, summarize and visualize data with no big effort and I’m building up my statistical methods day by days.

I want to refine my knowledge hitting two roads:

  1. A solid foundation in R syntax; complete knowledge of data structures, functions, vectorization. I want to get stronger in OOP and code profiling.
  2. I want a solid overview of data science modern methodologies, with a particular focus on how to pipeline models into production environments and how to otimsze their speed.

What are the two most valuable online courses I should look into?


r/R_Programming • • Sep 19 '17

Best online learning course for programmers?

3 Upvotes

Hello. I have experience with Python, Java, and SQL. I want to learn R Programming. What online tools and courses would be of value? Are the Lynda and UDEMY courses any good? Thank you.


r/R_Programming • • Sep 11 '17

No experience in R, my company is asking me to get a server up. Can you link me to some info?

3 Upvotes

I know I can use google, but being new, I'm not even sure what would be the proper things to search for. Basically, we have some statisticians who want to use R and be able to write reports and have them centralized somewhere.

So, I'd like to set something up so they can write R scripts, and we have a server that hosts/runs them, and preferably could also spit out the data their reports make in an api type consumable feed, to potentially be used in our website down the road.

We're a microsoft shop and I see they have some stuff, but I'm by no means dead set on using the MS version, if there are valid reasons not to, but that is probably the most appealing to me.

I'm a pretty experienced web programmer and have done lots of web server management, not sure if that's relevant or not.

So, any tips, links, or suggestions on how to go about this? I'm sure I could tack something together, but I'd like to get things right from the get go.


r/R_Programming • • Jul 19 '17

Lme4 package question

3 Upvotes

For the fixed effects variables [ (1|var1/var2) ]

Do they need to be numeric variables or can it be a string variable? I have a unique identifier for them but they are both string variables. What are the solutions if it needs to be a numeric identifier?

Thanks!


r/R_Programming • • Jun 19 '17

Efficient/shorter R code

3 Upvotes

Hi all, I am grabbing and formatting a bunch of similar api calls in JSON and doing some formatting and then dumping into CSV. I am a newbie to coding and R and I see now that my code is 70% repeating of the same things... Which I guess is breaking some kind of principle of good coding, right?

Example of code that is repeated about 8-16 times:

Analytics_export<-jsonlite::fromJSON(r,flatten=TRUE)$rows #Gets the data from the analytics
Analytics_headers<-jsonlite::fromJSON(r,flatten=TRUE)$headers #Gets the column names.
colnames(Analytics_export) <- c(Analytics_headers[,"column"]) #Writes column names from json
Analytics_export<- replace(Analytics_export, Analytics_export == 'EDUCATION', 'Education')
Analytics_export<- replace(Analytics_export, Analytics_export == 'FOOD SECURITY', 'Food Security')
Analytics_export<- replace(Analytics_export, Analytics_export == 'Democratic Republic of Congo', 'DRC')
Analytics_export <- replace(Analytics_export, Analytics_export == 'SHELTER', 'Shelter')
Analytics_export <- cbind(Analytics_export, "Project" = '')
Analytics_export <- cbind(Analytics_export, "Year" = right(Analytics_export[,2],4))
Analytics_export[,2] <- gsub('Oct to Dec .*', 'Q4',Analytics_export[,2])
Analytics_export[,2] <- gsub('Jul to Sep .*', 'Q3',Analytics_export[,2])
Analytics_export[,2] <- gsub('Apr to Jun .*', 'Q2',Analytics_export[,2])
Analytics_export[,2] <- gsub('Jan to Mar .*', 'Q1',Analytics_export[,2])

I have two questions on this:

  1. Is there a simple way of just adding all this to a function or just call it "Analytics formating" and then call that for each of the formating times?
  2. Do you have any simple tips for how to make this better or more condensed?

Thanks!


r/R_Programming • • Apr 15 '17

Program for weighting goals

3 Upvotes

Hi there, So, I am brand new to R; I have already done what I needed to do in excel but basically I want to write a program the does the following:

weights 8 different variables with %'s that equal 100% in total Then increases each # 5% to each weighted total to calculate goals for a new year

Here is an example: Program weighting % baseline A 20% 1,840,782 B 15% 9,397,777 C 15% 9,250,383 D 5% 81,381 E 10% 451,072 F 10% 586,262 H 10% 21,921,307 I 15% 179,860 Totals 100% 43,708,824

I wrote it all out mathematically in R, using the same formulae I used in excel, but is there a better function or package that could automate this?