r/R_Programming • u/SatoshiReport • Dec 31 '17
Is there a library for a client side secure websocket connection in R?
I have looked at webrockets which I do not believe supports wss and httpuv which is server side based. Any suggestions?
r/R_Programming • u/SatoshiReport • Dec 31 '17
I have looked at webrockets which I do not believe supports wss and httpuv which is server side based. Any suggestions?
r/R_Programming • u/selrok • Dec 27 '17
So I found the following [blog] (https://machinelearningmastery.com/machine-learning-in-r-step-by-step/) which basically compares multiple train models and I decided to give it a try. Now I've decided to do the same with a Raster image of a satellite and a shapefile, but the problem is that it takes way too much time to run the script, even with Parallel programming and splitting my data, but still they are way too much, is there a more efficient and faster way to run my script that you can suggest? Because by the time I run the third train() function my CPU goes from 1 to 100.
CPU: i7 6500U (2 Cores 4 Threads)
RAM: 4GB
DATA: Sentinel 1 image (15.5MB)
r/R_Programming • u/[deleted] • Dec 14 '17
Hello, I'm trying to take a large dataframe (~30,000 cols), chunk it into columns of 5, and perform functions on the chunks.
I've got the code for making a single chunk, but I'm struggling with how to make it iterate through the dataframe 5 at a time. My instinct is to try and make it work with apply, but I don't know where to start :(
Code so far:
chunkSize <- 5
startChunk <- 3 endChunk <- startChunk + (chunkSize - 1)
chunk <- df[,c(startChunk:endChunk)]
"chunk" is then subjected to a number of functions that saves an object made out of the chunk data.
Any help would be appreciated!
r/R_Programming • u/vallinatarajan • Nov 17 '17
In RHadoop, Iam getting the output for wordcount program, but the output is in an unreadable format. I want the output to be in keyvalue format.
Here is the code
hdfs.init()
map <- function(k,lines) { words.list <- strsplit(lines, '\s') words <- unlist(words.list) return( keyval(words, 1) ) }
reduce <- function(word, counts) { keyval(word, sum(counts)) }
wordcount <- function (input, output=NULL) { mapreduce(input=input, output=output, input.format="text", map=map, reduce=reduce) }
r/R_Programming • u/Tebasaki • Nov 13 '17
I'm trying to get a boxplot and histogram, and I keep getting an error
"Error in arrangeGrob(..., as.table = as.table, clip = clip, main = main, : object 'p1' not found Traceback:"
install.packages('gridExtra')
plotstats = function(df, col, bins = 30){
require(ggplot2)
require(gridExtra)
dat = as.factor('')
## Compute bin width
bin.width = (max(df[,col]) - min(df[,col]))/bins
## Plot a histogram
pl = ggplot(df, aes_string(col)) +
geom_histogram(binwidth = bin.width)
## A simple boxplot
p2 = ggplot(df, aes_string(dat, col)) +
geom_boxplot() + coord_flip() + ylab('')
## Now stack the plots
grid.arrange(p2, p1, nrow = 2)
}Then I run it. I know there's something I'm missing!
plotstats(dat, 'ArrDelay')r/R_Programming • u/Herbert_Westfall • Nov 06 '17
Hello, all, I am pasting my RMD file of a take home quiz. I posted all the questions, but question 4 is what I need help with. My regression line won't split at the threshold to create the discontinuity. Any help would be appreciated.
r/R_Programming • u/PRAJWALGMPP • Oct 25 '17
https://youtu.be/q8SzNKib5-4?t=920
If regexpr() gives the index of each string where the match begins and if the attribute "match.length" gives the length of each match, how is it possible that the first match begins at character 177 and has a length of 93 characters but the second match begins at 178th character itself and not at the character which is >(177+93=270)th character?
Also if you see the output of regexpr in the video, we see that there are three matches at the character index 178. How are multiple matches possible at the same place?
r/R_Programming • u/Animehurpdadurp • Oct 03 '17
Hi there. I hope I am using this subreddit correctly (so forgive me if I'm making any mistakes). I really need help figuring out why I cannot get this line graph to plot correctly. It's probably something really simple, but I am extremely new to programming and using R in general so go easy on me if it's a silly or obvious mistake. So for some reason, R keeps connecting the first and last points together on my graph instead of graphing the line chronologically like normal see link. If anyone could help me I would be so grateful. Thank you.
Code:
setwd("C:\Users\Hannah (lastname)\Documents\POE") df = read.csv("Poe's Short Stories.csv") pdf(file="LIWC_Plots_by_Year.pdf", width=15, height=5) x= df$Date y= df$WC plot(x,y, xlab="Date", ylab="WC", type= "o", col ="black") axis(side=1, at=seq(min(df$Date), max(df$Date), by=1)) title(main="WC Trend", xlab="Date", ylab="WC") dev.off()
r/R_Programming • u/agileguy1 • Oct 01 '17
r/R_Programming • u/chris-sam • Sep 20 '17
r/R_Programming • u/Gtrincao • Sep 08 '17
r/R_Programming • u/betamo • Sep 06 '17
Hello I have this data.frame and as you can see there are lists inside some cells.
myList1 <- list()
myList1[[1]] <- 0
myList1[[2]] <- list(3)
myList1[[3]] <- list(6)
myList1[[4]] <- list(7, 9)
myList <- list()
myList[[1]] <- list(1, 4, 6, 7)
myList[[2]] <- list(2, 7, 3)
myList[[3]] <- list(5, 5, 3, 9, 6)
myList[[4]] <- list(7, 9)
myDataFrame <- data.frame(row = c(1,2,3,4))
myDataFrame$col1 <- myList1
myDataFrame$col2 <- myListthe data frame looks like:
row col1 col2
1 0 list(1, 4, 6, 7)
2 list(3) list(2, 7, 3)
3 list(6) list(5, 5, 3, 9, 6)
4 list(7, 9) list(7, 9)How can I unlist the lists and collapse their items in order to make the dataframe look like the following ?
row col1 col2
1 0 1:4:6:7
2 3 2:7:3
3 6 5:5:3:9:6
4 7:9 7:9Thank you
r/R_Programming • u/abhi2001_001me • Sep 06 '17
r/R_Programming • u/hsmith9002 • Aug 14 '17
I have a data frame that has a coulm for gene symbols and a column for functional pathways. The values in the pathways column have many repeats as there are a number of genes that belong with each pathway. I would like to reorder this dataset so that each column is a single pathway and each row in those columns is a gene that belongs in that pathway? Any help would be greatly appreciated.
r/R_Programming • u/justinturn • May 23 '17
I'm trying to create a dataset using some government data. It's sort of inconsistent and contains a variety of information, from text notes to integers. I want to create a dataframe that contains only the integers and then column headers. With the random spacing and there being several 'matrices' of data, how can I do this? I appreciate your help!
Cattle Receipts: 7,465 Last Week: 7,552 Last Year: 5,979
Percent of supply: This Week Last Week Year Ago Feeders under 600 lbs 57 percent 66 percent 64 percent Feeders over 600 lbs 14 percent 12 percent 16 percent Slaughter cows 16 percent 9 percent 9 percent Replacement cows and Pairs 13 percent 14 percent 11 percent
The feeder supply included 56 percent steers/bulls and 44 percent heifers.
Compared to last week, slaughter cows and bulls sold steady. Feeder steers and heifers sold steady to 5.00 lower.
Please Note: The below USDA LPGMN price report is reflective of the majority of classes and grades of livestock offered for sale. There may be instances where some sales do not fit within reporting guidelines and therefore will not be included in the report. Prices are reported on a per cwt basis, unless otherwise noted.
Slaughter Cows: Breakers 70-80 percent lean 850-1200 lbs 54.00 -62.00 Boning 80-85 percent lean 850-1200 lbs 57.00 -64.00 Boning 80-85 percent lean 850-1200 lbs 64.00 -74.00 high yielding Lean 85-90 percent lean 850-1200 lbs 54.00 -66.00
Slaughter Bulls: Yield Grade 1-2
1000-1500 lbs 74.00-86.00; 1500-2000 lbs 84.00-95.00.
Feeder Steers: Medium and Large 1-2 200-300 lbs 185.00-200.00 few to 235.00; 300-350 lbs 180.00-190.00; 350-400 lbs 165.00-180.00; 400-500 lbs 150.00-166.00; 500-600 lbs 140.00-155.00; 600-700 lbs 135.00-150.00; 700-800 lbs 127.00-137.00.
Feeder Heifers: Medium and Large 1-2 200-250 lbs 175.00-195.00; 250-300 lbs 160.00-175.00; 300-400 lbs 145.00-160.00; 400-500 lbs 140.00-150.00; 500-600 lbs 135.00-148.00; 600-700 lbs 115.00-138.00; 700-800 lbs 115.00-124.00.
Cow/Calf Pairs: Medium and Large 1-2 2-8 years 850-1300 lbs with 100-300 lbs calves 1000.00-1500.00. Small and Medium 1-2 2-8 years 750-1100 lbs with 100-300 lbs calves 800.00-1100.00.
r/R_Programming • u/penguinsandR • May 12 '17
I'm trying to simulate trading on a time series for which I have produced trading signals using the portfolioSim package. The time series has only one security (as it is the result of a specific forecasting model for which I want to get an idea of potential profitability).
I run the following, basically following the template in the vignette, setting size to 1 as there is only one security that needs to be considered.
trades.interface <- new("stiFromSignal", in.var = "signal", equity = 1000000, size = 1,
rebal.on = periods$period)This however produces the following error (one for each period):
$`2015-08-14`
[1] "Error in weight(input, [email protected], object@type, object@size,
object@sides, : \n Size too large for the number of non-na ranks\n"There are no NA ranks.
I've tried other size = configurations such as "all" and the default "quintile". "all" returns the same error as above while "quintile" naturally returns a number less than one and results in this error:
$`2015-08-14`
[1] "Error in weight(input, [email protected], object@type, object@size,
object@sides, : \n Size is < 1 per side. Increase size parameter or
number non-na in.var values.\n"Can this package at all be applied to the modelling of a single security? and If so, what am I doing wrong/should I do?
r/R_Programming • u/andreykh • Apr 20 '17
r/R_Programming • u/neumanrq • Apr 20 '17
r/R_Programming • u/[deleted] • Apr 09 '17
I'm trying to make a plot to illustrate the wide sample-to-sample variability of the p-value (for power < 90% / small samples). I want the graph to look something similar to this: http://imgur.com/a/bO0YK So far I've created six sets of random values. Three of them are 10 element sets with mean = 3.4 and sd = 1. The other three are 10 element sets with mean = 2.9 and sd = 1. I want to make a plot that shows how the p-value varies widely for statistical tests with low power (i.e. small samples). Unsure of how to implement this in R. Any help would be appreciated.
r/R_Programming • u/zac_is_awesome • Mar 17 '17
I am trying to make a game where you make a charter jump and land (like geometry dash) please tell me how I can do this! I have it all on the same Y and X var. btw I am in JavaScript.
r/R_Programming • u/ashibs • Feb 07 '17
Hey guys!
I'm trying to simulate a data set, where I've created a data frame based on the data I had:
arabbarometer <- data.frame(c(resp = "I strongly agree", "I agree", "I disagree", "I strongly disagree"), fre = c(1147,2783,6116,3423))
BUT I'm trying to simulate the data in order to calculate the central tendencies more accurately. However, the code I have below is only producing 13,469 observations for 1 variable while I have four (see above) arabbar <- data.frame(sample(1:4, size = 13469, replace = TRUE, prob=c(0.08515851, 0.20662261, 0.45407974, 0.25413913)))
How can I fix that in my code? Is there a better code to simulate my data so I can proportionally attribute the sample size to the variables stated above?
r/R_Programming • u/falsestone • Jan 31 '17
Hey!
I've put together a pretty little PCA that's unfortunately neither pretty nor little. It's >40 data points, and I'd like to be able to visualize the relationship between related compounds in the PCA using color. For example, color all the herbicide data red and all the pesticide data blue.
How can I set multiple data points to display as the same color when plotted in R?
Thanks!
code is simple stuff right now, as follows:
library(ggplot2)
library(vegan)
library(ggbiplot)
library(ggfortify)
Avg_Conc_Overlap_color_xposed <- choose.files()
#above is selected from my computer's files, contents not important to this question
Avg_Conc_Data_color_xposed <- read.csv(Avg_Conc_Overlap_color_xposed)
df_color_xposed_no_S_no_At2Hy <- Avg_Conc_Data_color_xposed[c(2,3,4,5,6,7,8,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,41,42,43,44,45,46,47)]
PCA_plot_color_no_S_no_At2Hy <- autoplot(prcomp(df_color_xposed_no_S_no_At2Hy), data = Avg_Conc_Data_color_xposed, colour = 'Dates')
#above results in a beautiful display of rainbow-puke on a quadrant-plane--not very visually informative. This is the bit that needs to be fixed.r/R_Programming • u/[deleted] • Nov 03 '16
Any simple algorithm to write the game rather than use the package?
r/R_Programming • u/powerplay2009 • Sep 18 '16
I recently decided to change my computer over to dual-booting Linux (CentOS 7) and Windows, and because I like CentOS better, I am now using R more often there, from the terminal. Because I have a shared partition between my operating systems, and run R in both, it makes sense to have an R folder that each goes to by default.
In order to do that smoothly, I want to specify the default/startup directory that R goes to. I did that fine in Windows, using the Rprofile.site file. What I can't figure out is how to do the same thing in my Linux OS. I don't have an R folder in /bin/ or /etc/ and I can't find the Rprofile.site file. Anyone have experience with this that could help me out? I've tried googling but didn't find anything helpful.