r/learnR • • Nov 10 '22

Error while trying to compile report

Post image
0 Upvotes

r/learnR • • Jun 15 '22

Looking for answers to verify my practice

0 Upvotes
  1. Plot two vectors “x” and “y” of values (2,4,6,8,10) and(3,2,5,2,8) in a same graph. Limit y-axis to 12 and both the vectors should be displayed in different color and then create a title of that graph “DEMO”. (Points should be connected)

  2. Create a bar plot of number of magazines sold in a week where number of magazines sold in day1=4, day2=6, day3=7, day4=2, day5=6, day6=7, day7=9. X-axis shows days and Y-axis shows total number of magazine sold. Use density to differentiate the bars.

  3. Create a vector ‘a’ and store (10,9,8,7,6,5,4,3,2,1) into it. Access the first four values and then remove the last value from vector. Then display all elements whose value is more than 3.Then finally display all the values which are divisible by 2.

  4. Create a 4-d array with 4 rows and 5 columns with 3 tables and store value from 1 to 40. Display 3 columns.

  5. Create a list of 3 objects consist of bikes model, color and price. Then display each bike model along with its price and color.


r/learnR • • Nov 20 '20

Setting X-axis range on ggplot 2 hist

1 Upvotes

I am trying to create a hist of user ratings from google play apps.

When I try to make a basic hist

r <-ggplot( data= gp, aes(x=Rating))

r + geom_histogram()

the X axis range is from 0-20.

how do I change it to 1-5?


r/learnR • • Oct 24 '20

Regression

1 Upvotes

I’m looking to run a regression in R Studio. Either multiple or simple. Ideally I’d like parameter coefficients and standard errors. Is it possible to obtain an ANOVA table also?


r/learnR • • Jan 06 '20

Financial Modelling with R

1 Upvotes

Dear all,

I am working on a university project regarding CEO performance.

I was wondering if among all financial libraries in R there might be one, which provides historic data regrading the CEO timeslines i.e.

CEO 1 1st June 1994 - 31st March 2001

CEO 2 1st April 2001 - 31st August 2006

and so on

Thanks for any advice!


r/learnR • • Jul 14 '20

So I ran my t-test. Now how do I graph it?

1 Upvotes

I am an undergrad and am a little new to R. This may be trivial to you guys, but I have spent hours a day over the past few weeks watching videos just to get as far as I have. Now I've finally figured out how to get my t-tests done, but I can't figure out how to get them into a good looking graph to show my results. Please help! Here is one of the t-test results:

> t.test(consent$PuPSafeword, consent$RRSafeword, paired = TRUE)

Paired t-test 

data: consent$PuPSafeword and consent$RRSafeword

t = 11.307, df = 201, p-value < 2.2e-16

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval:

0.6948195 0.9883488

sample estimates:

mean of the differences

0.8415842


r/learnR • • Oct 03 '20

Integration of R in Tableau with use case of detection of multivariate outliers using SCRIPT_REAL()

Thumbnail
youtube.com
2 Upvotes

r/learnR • • Sep 09 '22

R vs Matlab

Thumbnail
startupunion.xyz
0 Upvotes

r/learnR • • Apr 06 '18

Itterating over collumns in a dataframe

3 Upvotes

In preparation for a data analysis thesis I am trying to teach myself some R by doing some small projects. At the moment I am trying to make summaries (for now) of each column in a data frame looking like this: column1: response dates column2: names column3-24: availability (either NO, or 1-3 choice) per date. (for example 1st of Jan, 5th of Jan, 1st of Feb, 20th of Feb etc..)

Now col_summary<-

  •    MyFile      %>%
  •    group_by(`1st of Jan`)%>%
  •    summarise(name_count=n())

gives my a perfect summary of the assurances of each response in the column. However so far I have not been able to iterate over the columns. Do you have a solution, or know a place I could find a tutorial on this?

Current code: for (i in MyFile) { col_summary<-

  •    MyFile      %>%
  •    group_by(`i`)%>%
  •    summarise(name_count=n())

col_summary


r/learnR • • May 26 '25

Question about the learning material

2 Upvotes

Hello,
I have been wandering for months between all the different types of materials without actually doing anything because I am not satisfied with anything, so I want to ask everyone for an opinion.
I followed a course in data analysis (although I don't recall much), and my professor advised me to focus more on practicing and reading articles, even though he did saw how much I suck (he said I should review the slides but I don't find them very complete).
I am currently preparing for a 6-month internship for my thesis, which will cover R applied to machine learning and data analysis for metabolomics data types.
I was thinking of following my professor's advice, using a dataset I create or find online to practice, and reading a lot of articles about my thesis topic. To understand more about the statistical part, I was thinking of using the book "Practical Statistics for Data Scientists" , but I am reading a lot of different reviews about it being good for beginners or not.
What do you think I should do? Sorry if it's messy


r/learnR • • Apr 14 '22

Having Issues with GGplot2

2 Upvotes

Hi all,

I am currently making some plots showing the most common industries in various towns on Long Island, NY. The plot itself looks pretty much exactly how I want except I can't seem to get the subtitle or caption I want into the final plot. Here is the code I am using:

hemp_occ_plot <- ggplot(aes(x = occ_cat, y = count), data = occ_hempstead)+
  geom_bar(stat = "identity", fill =c("#84D6B8", "#B8574D", "#B03B70", "#5AA197", "#21262A", "#724B65", "#772684", "#052A7F",  "#D08F70", "#A3B2D8", "#4B1F28", "#CEC67E", "#FE8EA4"))+
  ggtitle(label = "Most Common Industries Among Hemsptead Workers", subtitle = "Showing 408,460 Civilian Workers")+
  labs(x = NULL,
       y = "Workers per Industry", 
       caption = "Source: ACS, 2019")+
  theme(plot.title = element_text(family = "Arial", face = "bold", size = (15), hjust = -1, vjust = 0),
        plot.subtitle = element_text(family = "Arial", size = (12), hjust = -1, vjust = 0),
        axis.title.x = element_text(family = "Arial", size = (12), vjust = 1),
        axis.text.x = element_text(family = "Arial", size = (10)),
        axis.title.y = element_text(family = "Arial", size = (12)))+
  scale_x_discrete(limit = c("Agriculture_etal","Construction","Manufacturing","Wholesale_Trade","Retail_Trade","Transportation_Utilities","Information","Finance_Insurance_Realty","Professional","Eds_and_Meds","Entertainment_Hospitality","Other","Public_Administration"),
                   labels = c("Agriculture, Forestry, Fishing, Hunting, and Mining",
                              "Construction",
                              "Manufacturing",
                              "Wholesale Trade",
                              "Retail Trade",
                              "Transportation, Warehousing, and Utilities",
                              "Information",
                              "Finance, Insurance, Real Estate, Rental  and Leasing",
                              "Professional, Scientific, and Waste Management",
                              "Education, Health Care, and Social  Assistance",
                              "Arts, Entertainment, and Hospitality",
                              "Other Services, Except Public Administration",
                              "Public Administration"))+
  coord_flip()

And here is the resulting plot:

I have also had trouble picking out fonts and color palettes. I previously tried to use "Helvetica-Narrow" but the plot would just show up in Times New Roman when I did that. I also tried to using RColorBrewer to pick out a color palette, but just kept the same base color set instead of the palettes I indicated.

Any thoughts?


r/learnR • • Aug 03 '20

Unable to read CSV with `\,`

2 Upvotes

Hi, I have a CSV and one of its columns contains movie names without the quotes. So wherever there's a comma in the movie name, it's written as alpha\, beta. (I'm not allowed to just open the file and replace that, or even use anything other than readxl, dplyr, lubricate!)

I tried read.csv("file.csv", allowEscapes = TRUE) but it's still not reading them as it's supposed to. Apparently, the escape characters mentioned in the documentation are just \a, \b, \f, \n, \r, \t, \v, \040, \0x2A

I'm working with R for the first time, please bear with me if it's a stupid question, TIA!


r/learnR • • Jul 28 '20

Trying to use the count function on each numeric column of a data frame. Not sure why this doesn't work. . .

4 Upvotes
library(tidyverse)
map(iris[map_lgl(iris, is.numeric)], count)

 

Error in UseMethod("tbl_vars") : no applicable method for 'tbl_vars' applied to an object of class "c('double', 'numeric')"

I just want to apply the count() function to every numeric column in the iris data frame. I know I've done something like this before, I just can't figure out why this doesn't work. It does work with sum, which makes this more puzzling.

Edit: Kudos to /u/unclognition for pointing me in the right direction. The following is the solution.

map(iris, count, x = iris)

The issue was that the count function needs the data frame as the first argument. Map however would only pass the column as an argument. As a result, providing the x = iris as another parameter to map allows that to be passed to the count function and then the column is treated appropriately. The result is a frequency of all the values in the column with the associated counts.


r/learnR • • Apr 18 '20

Tidyverse filter questions - how to do a subset?

2 Upvotes

So I'm just getting out of tutorial hell this week and made some good progress on using R to do some useful data processing. I'm primarily leveraging tidyverse, with lubridate and some other packages as part of my experimenting and learning process.

One thing that seems somewhat different than a lot of the examples I look at in the tutorial are not quite the same kind of data I'm looking at, which tend to be time series around ad ad server delivery data. Because of this, I sometimes am at a loss how to do something specific, and would appreciate any pointers on how to think about this. While I have some idea how to try this under other programming languages, R seems to be its own special animal.

The issue--

Much of my data comes in a form like this:

DateDealImpressionsRevenue
2020-01-01Deal A353050250.01
2020-01-01Deal B353050135.10
2020-02-01Deal A353050236.96
2020-02-01Deal B353050101.45

...and for 30-100 deals, times 30-90 days, etc.

Much of my calculations require getting a 30-day, daily breakout report where I then want to do multiple looks and filters at the data. I've figured out a lot of this, but some of my analysis will require taking slices of that data, and looking at 7 day averages, 2 day averages (I do reports every other day), etc.

Additionally, with so many deals, charting (part of what I'm learning and experimenting with) gets very awkward when you are trying to look at a specific deal or a small group of deals. I'm still working out the best way to do this, and honestly this has been my biggest long-term challenge while trying to apply R to my work vs. using something like Python, which I'm also learning. R doesn't seem cut out for this kind of data, but it may well just be my mistaken perception vs. not knowing enough yet.

What I'm having problems wrapping my head around is how to do a filter where it creates a tibble, from this same 30-day daily data file, of deals that have only passed a certain 7-day threshold? There must be a way to do this, and I am trying to not make like 4 different tibbles, or at least if I do, be able to then use one tibble that has a shorter list to then filter the other tibbles from.

I can figure out how to make a summary of the past 7 days, how to then boil that down into a simple avg. or summary per deal, even how to make that a short list above X dollar amount, but how do I then go back to the 30-day, all deals tibble and filter against that for a chart, a report, other calcs, etc.? The only ways I can think how seem very awkward and when I look at long-term code maintenance and making functions, I'm having a hard time wrapping my head around it.

So, some code samples:

Let's say df4 below is a tibble where I have already done some changes to rename columns and format dates to make them R friendly. So one thought was, make a df7day tibble where I have a list of averages or summaries that I can then return back to the original tibble with some useful info about what I want to look at and recalculate:

df7day <- df4 %>% filter(Day <= Dayx & Day >= Dayx7) %>% 
  group_by(Deal) %>% summarize(mean(Revenue)) %>% 
  arrange(desc(`mean(Revenue)`)) %>% transmute(Deal, Avg_revenue = `mean(Revenue)`)

Is there to do this when I make a tibble, like a df5 or so forth, so that I don't have to always make this second tibble to sort against? Speaking of which, how do I turn around and use this df7day tibble to even do any filtering against the df4 tibble?

Thanks in advance to anyone who made it this far. I really like R, I hope I can get better at it.


r/learnR • • Apr 11 '19

Best websites/tools to learn R?

5 Upvotes

This might be a duplicate question but I was looking for any datasets/websites to help me develop R, I have basic knowledge but I want to see how I can apply the language


r/learnR • • Nov 08 '19

Converting datetimes without leading zeros to POSITX

2 Upvotes

I have a datetime column in my dataset that is formatted like so:

20-9-2019 17:44 where the month is not zero padded. This breaks the ability to do the following:

df$datetime <- as.POSIXct(df$Time.stamp, format="%m-%d-%Y %H:%M")

This is driving me mad. Is there a simple way to fix this?


r/learnR • • Oct 24 '18

Tips for scaling ggplotly chart in code PowerBI?

Post image
2 Upvotes

r/learnR • • Jul 04 '19

Help with a code....

3 Upvotes

beginner here. doing an online tutorial that does not have answers.

Q: Make a vector from 1 to 100. Make a for-loop which runs through the whole vector. Multiply the elements which are smaller than 5 and larger than 90 with 10 and the other elements with 0.1.

my code:

h=seq(from=1,to=100,by=1) g=c() for(i in 1:100) { if(h[i]<5&h[i]>90) {g[i]=h[i]*10 }else{ g[i]=h[i]*0.1} } print(g)

I am getting hananswer where everything is multiplied by 0.1

ans:

[1] 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3 1.4 1.5 1.6 [17] 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 [33] 3.3 3.4 3.5 3.6 3.7 3.8 3.9 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 [49] 4.9 5.0 5.1 5.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 6.0 6.1 6.2 6.3 6.4 [65] 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.0 [81] 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.0 9.1 9.2 9.3 9.4 9.5 9.6 [97] 9.7 9.8 9.9 10.0

How do I fix this? Thank you.


r/learnR • • Jan 22 '19

After library(swirl)?

1 Upvotes

I just finished going through some datacamp lessons and the swirl package

I’m new to R but have a good understanding of statistics from using SPSS through my undergraduate so where would you recommend I continue learning R?

Should I just start messing around or are there any more advanced packages that could show me ropes I’m R? Particularly for multivariate?

Any suggestions are welcome and thanks!


r/learnR • • Sep 07 '19

help with code, factor command

2 Upvotes

Hi, Im a beginner here so try and take it easy on me. Ill do my best to try and explain my situation, Im using R Studios FYI

Im trying to do this online homework and the prof isnt really being all that helpful. We have a data set, one of the variables is titles jobs, its populated with nominal data points ( like 0, 1, 2,3 the numbers arent a count of how many jobs, but rather the number corresponds to a position like accountant, mechanic etc)

he wants us to make this variable a factor i thought it would be a rather simple thing however turns out Im wrong.

I thought it would be just factor(job) but that wont run, I keep getting the error" Error in factor(job) : object 'job' not found"

Any help is appreciated


r/learnR • • Nov 04 '22

Move plot closer to the y-axis

Thumbnail
self.rprogramming
2 Upvotes

r/learnR • • Nov 02 '22

why does my Geom_bar() exclude NA's?

Post image
1 Upvotes

r/learnR • • Nov 18 '22

Create custom `ggplot2` candlesticks `geom` based on two other `geom`s

Thumbnail
self.rlanguage
1 Upvotes

r/learnR • • May 15 '21

Help finding resources to answer part C of the question please ?

Thumbnail
gallery
6 Upvotes

r/learnR • • May 26 '21

Where can I view projects in R?

2 Upvotes

Does anyone know where I can find project examples in R? Preferably more simple and beginner-friendly, but Id also love to take a look at what real-life projects are like.

I've learned some basic stuff in swirl but I feel that it would be easier to understand topics by seeing them in use.