Sorting Data from Excel - Not Sure Where to Begin (for non-programming class assignment)

Hi. I'm brand new to R Studio, which was just announced as part of class this week. The professor gave an assignment that basically expects us all to be pros at this language. I'm not a programmer and this is not a programming class, it's accounting.

Whatsmore, the professor has yet to tell us how to do anything except calculate a mean. Somehow we are just expected to learn this.

**The manuals and videos do not help me. I need someone to explain something. I'm not even sure where to start with figuring this out. **

Here's what we need to do: import data from Excel and then classify it into categories based on ranges of numbers. All of the data is a number from 1 to 6. We are supposed to put it into three categories (1 and 2 in one, 3 and 4 in another, 5 and 6 in another). These are results from a survey.

I know how to get the spreadsheet in, but how do I do the following?

  • have the computer read the data from the first column in Excel
  • create a variable
  • come up with some way to sort it as mentioned above

Again, don't just refer me to some manual that I can't understand or some video. I need some direct answers please. Thanks.

You must have been given some pointers on how to do this? Being able to acquire knowledge to solve novel problems is highly valuable, so perhaps you are ment to solve this by putting the pieces together after reading and seeing relevant materials and perhaps doing some digging on the interenet? Also, consider discussing the assignment with your fellow students and get peer feedback on your suggestions.

Happy learning!

No. We were not given pointers. We were told how to import things into a program but nothing more. I've tried searching the internet, but how can you possibly start doing anything when you don't understand the manuals that are out there and need explanation?

Everything seems written for computer people. I need someone to help explain this stuff to me in a non-computer person way. Thanks.

If you are to learn to use R, you will have to put in the time, there are no short cuts. While it can be frustrating and I realise that you are looking for "direct answers", simply being given the exact code, will teach you nothing. Even if as you state "this is not a programming class, it's accounting", I would argue that to a large extend, working with numbers is programming.

As I wrote, look carefully at your materials and discuss the assignment with your fellow students. There must be some pointers in your learning materials.

An excelent ressource, that I would recommend you to have a look at is the "R for Data Science" book:

Happy learning!

1 Like

I agree you will have to learn to work through the documentation and other resources but I also understand that getting started can be very frustrating. Here is a simple example that might be close to what you want to do. You need to compare this example to the help file for the cut() function. Run ?cut to see that. Test what happens when you change the values of breaks or delete include.lowest = TRUE, or delete labels = FALSE. If you have questions, ask them here. Your professor might expect you to use some other method. There are several ways to do most things in R. At the very least, be able to explain why your method works.

# Invent some data
DF <- data.frame(Score = c(4,6,1,3,2,4,3,5,1,3,4),
                 Name = LETTERS[1:11])
#look at the data
#>    Score Name
#> 1      4    A
#> 2      6    B
#> 3      1    C
#> 4      3    D
#> 5      2    E
#> 6      4    F
#> 7      3    G
#> 8      5    H
#> 9      1    I
#> 10     3    J
#> 11     4    K
#Use the cut() function to bin the data
DF$bin <- cut(x = DF$Score, breaks = c(1,2,4,6),include.lowest = TRUE,
              labels = FALSE)
#Look at the modified data
#>    Score Name bin
#> 1      4    A   2
#> 2      6    B   3
#> 3      1    C   1
#> 4      3    D   2
#> 5      2    E   1
#> 6      4    F   2
#> 7      3    G   2
#> 8      5    H   3
#> 9      1    I   1
#> 10     3    J   2
#> 11     4    K   2

Created on 2023-03-28 with reprex v2.0.2

1 Like

FJCC, thanks for actually providing some code, but I have NO idea what it means. I'm guessing the c is some variable? Is that how we define it? Like if I wanted to call the variable "price", for example, would I put that where the c is?

How do we get to the chart? How do we grab the column from Excel?

My problem with the documentation is that it doesn't say what does what. I need one of those "for Dummies" books that explains things in conversational English, not something geared at computer jocks who program for a living and pick up on this quickly.

The documentation is like if Tiger Woods were teaching someone how to golf when he's the best of all time and probably has more natural ability than any of us--I need someone who isn't PGA caliber to teach me who has struggled just to play Par 3 if you get my drift.

Rather than spending time explaining my example which turned out to not be useful, let's work with what you are doing. How did you read in the data from the Excel file? Please show the code you ran or otherwise explain what you did. I will then try to explain what you did and how to work further with it. However, I can't be a replacement for a whole course on R. You will have to find a beginners guide that works for you. I hope that after a little explanation, the guides will seem less obscure.

Welcome to the forum. R can be a bit daunting at first. If you are used to other statistics packages it can be shocking. Still, once you have used it a bit it is a very nice tool.

I think that one of the best short intros to R is Preceptor’s Primer for Bayesian Data Science: Using the Cardinal Virtues for Inference

1 Like

There was some button I pressed to make it read the Excel file. It was one where I had to navigate to the file on the computer and put it in.

The professor posted a video and it was only marginally useful. There's something about a "case_when" that uses data ranges. I'm just going to copy down everything and change the numbers from the example. It seems most things on here should work that way, but... to tally up something across a row and then report it for a given client? Not a column this time, a cell A1, B1, C1, D1, then output a total based on these numbers at the end of the row?

Please don't tell me "read the manual". I just need a direct answer and I'm tired of people telling me to find a book or a video. I just want to pass this assignment so I know what to do in the future. So far this forum has been less than useful in answering questions and more about telling me to go get books; I understand if you are authors promoting your product, but I'm just very frustrated and doing something that wasn't even in the course description with this.

It's understandable that you are frustrated. If you are being asked to write a program in R with no guidance or experience, that's pretty unreasonable.

If you really want an R for Dummies book, you might look at

Whether it's good or not, I don't know.

No one is going to do your assignment for you. And even if you're understandable frustrated, don't take it out on people here trying to help you. @jrkrideau and @FJCC are among the most helpful here.


OK, you have your data read into R and an example of a case_when() to work with. If you tell us the name that was given to the Excel data when it was read in and show the case_when() code that your professor provided, we can probably make some progress. It would also help if you showed the output of using the colnames() function on your Excel data. That will show all the column names of the data. If the data were read into a variable named DF, run


in the console (the lower left pane of RStudio) and copy the output here.

1 Like

Startz suggested the R for Dummies book. That is where I began my R education, starting at zero knowledge of R, and I think it was the perfect start. I self-studied the book, and ran many of the author's examples myself to try to understand what the programs did. I recommend this approach.

1 Like

While your frustration is understandable, you have to accept that you will have to crawl before you can run. I guarantee you, that if you put in the time and effort and learn R, you will not regret it and it will benefit you greatly in your career. And no, this is not down to "bro"-gramming-talk, it is accepting that in today's world, working with numbers is programming and programming is not only writing specific code, it is a mindset, a way of thinking, which can be applied beyond writing code.

You have your materials, you have your assignment and you've gotten several hints from this forum. Find your inner patience, talk to your fellow students and start crawling :+1:

Happy leaRning!


I recommend the course I just did for newbies: R Programming at Google Coursera

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.