Error: Object "seat1" Not Found

Hello, I am new to learning R (mostly through datacamp) and it appears the dataset I'm trying to work with is loaded correctly. It is a .csv file with variable names as the columns and data for each participant in each row. Each column is an item from a scale (e.g. SEAT1-SEAT24, RSE1-RSE10). I'm a psychologist and created a scale with my psych testing class in the spring. I'm also much more used to programs like SPSS, JASP, and JAMOVI, so this has been challenging.

I'll try to include screen capture, but the data set looks like this....

SEAT1 SEAT2 SEAT3
5 7 1
2 6 5

I attempted to sum the SEAT items by entering (for example)

sum(SEAT1, SEAT2, SEAT3)

and I get back an error stating that the object 'seat1' is not found. When I call up variable names it lists all of the 60 columns for the different variables I have. So its all in there.

I'm sure I'm missing something and appreciate any thoughts you may have. Thank you!!

I would usually reshape the data to have a column describing the variable and a column for the value. Nevertheless, here are some ways to sum an entire data frame or a subset of the columns.

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
df <- data.frame(Seat1 = 1:5, Seat2 = 6:10, Seat3 = 11:15, NotSeat1 = 1:5)
df
#>   Seat1 Seat2 Seat3 NotSeat1
#> 1     1     6    11        1
#> 2     2     7    12        2
#> 3     3     8    13        3
#> 4     4     9    14        4
#> 5     5    10    15        5
sum(df)
#> [1] 135

#select columns whose name starts with Seat
df2 <- df %>% select(starts_with("Seat"))
df2
#>   Seat1 Seat2 Seat3
#> 1     1     6    11
#> 2     2     7    12
#> 3     3     8    13
#> 4     4     9    14
#> 5     5    10    15
sum(df2)
#> [1] 120

Created on 2019-08-14 by the reprex package (v0.2.1)

Hi, and welcome to the community!

FJCC has already provided you a solution. I just wanted to add to it that the reason you're having problems.

First of all, this is very unlikely to get this specific error: object 'seat1' is not found from the call sum(SEAT1, SEAT2, SEAT3), because variable names in R are case sensitive. Are you sure you haven't used lowercase characters in the sum call?

Also, most likely you haven't defined the variables SEAT1, SEAT2, etc in the global environment separately. These are the column names present in seatworking, which is in global environment. While R can access that data.frame (or matrix, can't be sure from the screenshot) directly, it doesn't recognise its columns automatically. You'll have to attach specifically, though probably that's not a good choice. You should make more uses of $, [, [[ etc., and you can also use with and within.

Also, another note is that please do not post screenshots for your future threads. For this particular question, it doesn't matter much as it was possible to figure out the problem, but usually people on this community will try to run your code first to see what kind of problems you're facing and then will suggest solutions to help you solve the problem yourself. Screenshots are obstacles in that, as it isn't copy paste friendly. The better way will be provide a reproducible example of your problem which help others to help you.

Please go through the following threads before asking questions in future:

  1. FAQ: Tips for writing R-related questions
  2. FAQ: How to do a minimal reproducible example ( reprex ) for beginners
  3. FAQ: Tips for Introducing Non-Programming-Problem Discussions

Hope this helps.

Hi @ericphd! Yours is a common situation. You might find these articles, examples, and books helpful, since they're aimed directly at people trying to translate their prior experience with other statistical software into R terms: http://r4stats.com/

We also have a whole thread on this site where people chimed in with their favorite resources for people new to R:

And of course, please keep asking questions here :grinning: