object not found 'object'

Hi i have a simple problem, I included sav dataset to my script and wanted to make simple histogram of one of the elements. But anything i choose to make histogram of i get error object not found 'object'.
When i make ls(mydata) it says that elements exists so i dont know why this error appears. thanks

library(foreign)
file.choose()
mydata = read.spss("C:\Users\sth\Downloads\bank_defaults.sav", to.data.frame = TRUE)
hist(employ)

Hi @hypia, could you apply the dput() function to mydata and paste the output here, like this?

```
<--- paste output of dput(head(mydata, 50)) here
```

(Make sure to paste between a pair of triple backticks (```), which makes it easier for folks to help by recreating your context.)

thats the output

structure(list(age = c(41, 27, 40, 41, 24, 41, 39, 43, 24, 36,
27, 25, 52, 37, 48, 36, 36, 43, 39, 41, 39, 47, 28, 29, 21, 25,
45, 43, 33, 26, 45, 30, 27, 25, 25, 26, 30, 32, 28, 45, 23, 34,
42, 39, 26, 21, 35, 47, 23, 35), ed = structure(c(3L, 1L, 1L,
1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
3L, 1L, 1L, 1L, 1L, 2L, 4L, 2L, 1L, 2L, 3L, 1L, 1L, 3L, 1L, 1L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 1L), .Label = c("Did not complete high school",
"High school degree", "Some college", "College degree", "Post-undergraduate degree"
), class = "factor"), employ = c(17, 10, 15, 15, 2, 5, 20, 12,
3, 0, 0, 4, 24, 6, 22, 9, 13, 23, 6, 0, 22, 17, 3, 8, 1, 0, 9,
25, 12, 2, 3, 1, 2, 8, 8, 6, 10, 12, 1, 23, 7, 17, 7, 19, 0,
0, 13, 4, 0, 18), address = c(12, 6, 14, 14, 0, 5, 9, 11, 4,
13, 1, 0, 14, 9, 15, 6, 6, 19, 9, 21, 3, 21, 6, 6, 2, 2, 26,
21, 8, 1, 15, 10, 7, 4, 1, 7, 4, 1, 8, 5, 2, 3, 23, 5, 0, 1,
15, 2, 2, 2), income = c(176, 31, 55, 120, 28, 25, 67, 38, 19,
25, 16, 23, 64, 29, 100, 49, 41, 72, 61, 26, 52, 43, 26, 27,
16, 32, 69, 64, 58, 37, 20, 22, 26, 27, 35, 45, 22, 54, 24, 50,
31, 59, 41, 48, 14, 16, 35, 26, 21, 42), debtinc = c(9.3, 17.3,
5.5, 2.9, 17.3, 10.2, 30.6, 3.6, 24.4, 19.7, 1.7, 5.2, 10, 16.3,
9.1, 8.6, 16.4, 7.6, 5.7, 1.7, 3.2, 5.6, 10, 9.8, 18, 17.6, 6.7,
16.7, 18.4, 14.2, 2.1, 10.5, 6, 14.4, 2.9, 26, 16.1, 14.4, 17.1,
4.2, 6.6, 8, 4.6, 13.1, 7.5, 6.8, 4.5, 10.4, 11.4, 7.4), creddebt = c(11.359392,
1.362202, 0.856075, 2.65872, 1.787436, 0.3927, 3.833874, 0.128592,
1.358348, 2.7777, 0.182512, 0.252356, 3.9296, 1.715901, 3.7037,
0.817516, 2.918216, 1.181952, 0.563274, 0.099008, 1.154816, 0.587552,
0.4316, 0.402192, 0.24192, 2.14016, 0.707319, 0.951232, 3.084208,
0.204906, 0.105, 1.13883, 0.72228, 1.018656, 0.07714, 6.0489,
1.409716, 3.195936, 1.337904, 0.5586, 0.33759, 1.80776, 0.941114,
1.930416, 0.3024, 0.150144, 0.43155, 0.12168, 0.775656, 0.205128
), othdebt = c(5.008608, 4.000798, 2.168925, 0.82128, 3.056564,
2.1573, 16.668126, 1.239408, 3.277652, 2.1473, 0.089488, 0.943644,
2.4704, 3.011099, 5.3963, 3.396484, 3.805784, 4.290048, 2.913726,
0.342992, 0.509184, 1.820448, 2.1684, 2.243808, 2.63808, 3.49184,
3.915681, 9.736768, 7.587792, 5.049094, 0.315, 1.17117, 0.83772,
2.869344, 0.93786, 5.6511, 2.132284, 4.580064, 2.766096, 1.5414,
1.70841, 2.91224, 0.944886, 4.357584, 0.7476, 0.937856, 1.14345,
2.58232, 1.618344, 2.902872), default = structure(c(2L, 1L, 1L,
1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L), .Label = c("No",
"Yes"), class = "factor"), preddef1 = c(0.808394327359702, 0.198297476159104,
0.0100361080990023, 0.0221382837594812, 0.781588314152869, 0.216708941468906,
0.18596010843841, 0.014708653491152, 0.748041203606411, 0.815057013081852,
0.350309226043236, 0.239053902326814, 0.00979017347264589, 0.364494047547502,
0.0118739038464262, 0.0967040778565908, 0.212050390551138, 0.00140487060255445,
0.104145390281715, 0.0919180135014027, 0.0043735364616344, 0.00304735236249091,
0.293932179671944, 0.106799619753194, 0.629777455306767, 0.861313401393958,
0.0164611579900324, 0.00143799346726798, 0.276706675474106, 0.50332186742386,
0.0764195852261632, 0.433699425118601, 0.288738875933443, 0.231100684278883,
0.0749571955933729, 0.950053516816289, 0.211956403647939, 0.335996915257273,
0.643903295283559, 0.00226875357862989, 0.132878207080903, 0.0317685432338983,
0.0319034793260759, 0.0280793313767151, 0.511049960032338, 0.453616874344579,
0.0107818887723767, 0.281657372501201, 0.621784769760648, 0.0104607182588521
), preddef2 = c(0.788640431821437, 0.128445387038174, 0.00298677834821412,
0.0102732648580009, 0.737884820480045, 0.328194657083002, 0.179255712952496,
0.010572667741295, 0.619443452160334, 0.79722745061275, 0.610511356012177,
0.219023649798498, 0.00628468428836779, 0.340467555901854, 0.00771406996447905,
0.113839681770466, 0.175024767261369, 0.000563999860427421, 0.092729658950997,
0.0869105909754819, 0.00164474095768356, 0.00201376135654785,
0.236041924669508, 0.204130576692517, 0.620461226408894, 0.773743765928539,
0.01520071605721, 0.000641927515098064, 0.219532599900222, 0.479453765995919,
0.0529185951936342, 0.405229108934149, 0.233062013435398, 0.177802520204962,
0.0480042726553067, 0.946420103718697, 0.25417611027888, 0.417417714105591,
0.659599885195508, 0.0014604870209812, 0.097419360235256, 0.0622616484352908,
0.0307905348504762, 0.0102963057292182, 0.749382132397176, 0.376452011382485,
0.00703764487094369, 0.363860690914129, 0.63595566508835, 0.00432423778400214
), preddef3 = c(0.213043376128119, 0.436903005506046, 0.141022623460993,
0.104422211934525, 0.436903005506046, 0.233577086224484, 0.817091719095171,
0.113357560419516, 0.663903973464324, 0.515530082740544, 0.0905475842743514,
0.136307035904262, 0.228897785847298, 0.4048353225734, 0.208663437695647,
0.198005125485801, 0.408010484205201, 0.17793130940947, 0.144241548322777,
0.0905475842743514, 0.108172886416567, 0.142624515618002, 0.228897785847298,
0.224284794561537, 0.459685523765733, 0.446640081169066, 0.161260140498931,
0.417581158840994, 0.472786447367334, 0.340345791526492, 0.0949774523057643,
0.240719879471011, 0.149184219573304, 0.346280273672069, 0.104422211934525,
0.709164136909414, 0.398509074529238, 0.346280273672069, 0.430438062072136,
0.121540265102462, 0.159487876633662, 0.185763039434584, 0.127274196819662,
0.308629906178795, 0.176014277117858, 0.163048277810623, 0.125819411565012,
0.23832247968374, 0.263029539285341, 0.1741135244113)), variable.labels = c(age = "Age in years",
ed = "Level of education", employ = "Years with current employer",
address = "Years at current address", income = "Household income in thousands",
debtinc = "Debt to income ratio (x100)", creddebt = "Credit card debt in thousands",
othdebt = "Other debt in thousands", default = "Previously defaulted",
preddef1 = "Predicted default, model 1", preddef2 = "Predicted default, model 2",
preddef3 = "Predicted default, model 3"), codepage = 1250L, row.names = c(NA,
50L), class = "data.frame")

@hypia I think the issue is that you're not referencing the data frame in the call to hist(). Try hist(mydata$employ)` instead and see if that works.

that worked thanks a lot!

And here's a way to easily view the contents of your data frame -- just copy and paste the following code and it should work for you, as long as you install the tidyverse package first:

library(tidyverse)
mydata <- 
  structure(list(age = c(41, 27, 40, 41, 24, 41, 39, 43, 24, 36, 
                         27, 25, 52, 37, 48, 36, 36, 43, 39, 41, 39, 47, 28, 29, 21, 25, 
                         45, 43, 33, 26), ed = structure(c(3L, 1L, 1L, 1L, 2L, 2L, 1L, 
                                                           1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 3L, 1L, 1L, 1L, 
                                                           1L, 2L, 4L, 2L, 1L, 2L, 3L), .Label = c("Did not complete high school", 
                                                                                                   "High school degree", "Some college", "College degree", "Post-undergraduate degree"
                                                           ), class = "factor"), employ = c(17, 10, 15, 15, 2, 5, 20, 12, 
                                                                                            3, 0, 0, 4, 24, 6, 22, 9, 13, 23, 6, 0, 22, 17, 3, 8, 1, 0, 9, 
                                                                                            25, 12, 2), address = c(12, 6, 14, 14, 0, 5, 9, 11, 4, 13, 1, 
                                                                                                                    0, 14, 9, 15, 6, 6, 19, 9, 21, 3, 21, 6, 6, 2, 2, 26, 21, 8, 
                                                                                                                    1), income = c(176, 31, 55, 120, 28, 25, 67, 38, 19, 25, 16, 
                                                                                                                                   23, 64, 29, 100, 49, 41, 72, 61, 26, 52, 43, 26, 27, 16, 32, 
                                                                                                                                   69, 64, 58, 37), debtinc = c(9.3, 17.3, 5.5, 2.9, 17.3, 10.2, 
                                                                                                                                                                30.6, 3.6, 24.4, 19.7, 1.7, 5.2, 10, 16.3, 9.1, 8.6, 16.4, 7.6, 
                                                                                                                                                                5.7, 1.7, 3.2, 5.6, 10, 9.8, 18, 17.6, 6.7, 16.7, 18.4, 14.2), 
                 creddebt = c(11.359392, 1.362202, 0.856075, 2.65872, 1.787436, 
                              0.3927, 3.833874, 0.128592, 1.358348, 2.7777, 0.182512, 0.252356, 
                              3.9296, 1.715901, 3.7037, 0.817516, 2.918216, 1.181952, 0.563274, 
                              0.099008, 1.154816, 0.587552, 0.4316, 0.402192, 0.24192, 
                              2.14016, 0.707319, 0.951232, 3.084208, 0.204906), othdebt = c(5.008608, 
                                                                                            4.000798, 2.168925, 0.82128, 3.056564, 2.1573, 16.668126, 
                                                                                            1.239408, 3.277652, 2.1473, 0.089488, 0.943644, 2.4704, 3.011099, 
                                                                                            5.3963, 3.396484, 3.805784, 4.290048, 2.913726, 0.342992, 
                                                                                            0.509184, 1.820448, 2.1684, 2.243808, 2.63808, 3.49184, 3.915681, 
                                                                                            9.736768, 7.587792, 5.049094), default = structure(c(2L, 
                                                                                                                                                 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
                                                                                                                                                 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L), .Label = c("No", 
                                                                                                                                                                                                                     "Yes"), class = "factor"), preddef1 = c(0.808394327359702, 
                                                                                                                                                                                                                                                             0.198297476159104, 0.0100361080990023, 0.0221382837594812, 
                                                                                                                                                                                                                                                             0.781588314152869, 0.216708941468906, 0.18596010843841, 0.014708653491152, 
                                                                                                                                                                                                                                                             0.748041203606411, 0.815057013081852, 0.350309226043236, 
                                                                                                                                                                                                                                                             0.239053902326814, 0.00979017347264589, 0.364494047547502, 
                                                                                                                                                                                                                                                             0.0118739038464262, 0.0967040778565908, 0.212050390551138, 
                                                                                                                                                                                                                                                             0.00140487060255445, 0.104145390281715, 0.0919180135014027, 
                                                                                                                                                                                                                                                             0.0043735364616344, 0.00304735236249091, 0.293932179671944, 
                                                                                                                                                                                                                                                             0.106799619753194, 0.629777455306767, 0.861313401393958, 
                                                                                                                                                                                                                                                             0.0164611579900324, 0.00143799346726798, 0.276706675474106, 
                                                                                                                                                                                                                                                             0.50332186742386), preddef2 = c(0.788640431821437, 0.128445387038174, 
                                                                                                                                                                                                                                                                                             0.00298677834821412, 0.0102732648580009, 0.737884820480045, 
                                                                                                                                                                                                                                                                                             0.328194657083002, 0.179255712952496, 0.010572667741295, 
                                                                                                                                                                                                                                                                                             0.619443452160334, 0.79722745061275, 0.610511356012177, 0.219023649798498, 
                                                                                                                                                                                                                                                                                             0.00628468428836779, 0.340467555901854, 0.00771406996447905, 
                                                                                                                                                                                                                                                                                             0.113839681770466, 0.175024767261369, 0.000563999860427421, 
                                                                                                                                                                                                                                                                                             0.092729658950997, 0.0869105909754819, 0.00164474095768356, 
                                                                                                                                                                                                                                                                                             0.00201376135654785, 0.236041924669508, 0.204130576692517, 
                                                                                                                                                                                                                                                                                             0.620461226408894, 0.773743765928539, 0.01520071605721, 0.000641927515098064, 
                                                                                                                                                                                                                                                                                             0.219532599900222, 0.479453765995919), preddef3 = c(0.213043376128119, 
                                                                                                                                                                                                                                                                                                                                                 0.436903005506046, 0.141022623460993, 0.104422211934525, 
                                                                                                                                                                                                                                                                                                                                                 0.436903005506046, 0.233577086224484, 0.817091719095171, 
                                                                                                                                                                                                                                                                                                                                                 0.113357560419516, 0.663903973464324, 0.515530082740544, 
                                                                                                                                                                                                                                                                                                                                                 0.0905475842743514, 0.136307035904262, 0.228897785847298, 
                                                                                                                                                                                                                                                                                                                                                 0.4048353225734, 0.208663437695647, 0.198005125485801, 0.408010484205201, 
                                                                                                                                                                                                                                                                                                                                                 0.17793130940947, 0.144241548322777, 0.0905475842743514, 
                                                                                                                                                                                                                                                                                                                                                 0.108172886416567, 0.142624515618002, 0.228897785847298, 
                                                                                                                                                                                                                                                                                                                                                 0.224284794561537, 0.459685523765733, 0.446640081169066, 
                                                                                                                                                                                                                                                                                                                                                 0.161260140498931, 0.417581158840994, 0.472786447367334, 
                                                                                                                                                                                                                                                                                                                                                 0.340345791526492)), variable.labels = c(age = "Age in years", 
                                                                                                                                                                                                                                                                                                                                                                                          ed = "Level of education", employ = "Years with current employer", 
                                                                                                                                                                                                                                                                                                                                                                                          address = "Years at current address", income = "Household income in thousands", 
                                                                                                                                                                                                                                                                                                                                                                                          debtinc = "Debt to income ratio (x100)", creddebt = "Credit card debt in thousands", 
                                                                                                                                                                                                                                                                                                                                                                                          othdebt = "Other debt in thousands", default = "Previously defaulted", 
                                                                                                                                                                                                                                                                                                                                                                                          preddef1 = "Predicted default, model 1", preddef2 = "Predicted default, model 2", 
                                                                                                                                                                                                                                                                                                                                                                                          preddef3 = "Predicted default, model 3"), codepage = 1250L, row.names = c(NA, 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                    30L), class = "data.frame")
# end of 'structure()' command

# convert data frame to tibble
as_tibble(mydata)
#> # A tibble: 30 x 12
#>      age ed    employ address income debtinc creddebt othdebt default
#>    <dbl> <fct>  <dbl>   <dbl>  <dbl>   <dbl>    <dbl>   <dbl> <fct>  
#>  1    41 Some…     17      12    176     9.3   11.4     5.01  Yes    
#>  2    27 Did …     10       6     31    17.3    1.36    4.00  No     
#>  3    40 Did …     15      14     55     5.5    0.856   2.17  No     
#>  4    41 Did …     15      14    120     2.9    2.66    0.821 No     
#>  5    24 High…      2       0     28    17.3    1.79    3.06  Yes    
#>  6    41 High…      5       5     25    10.2    0.393   2.16  No     
#>  7    39 Did …     20       9     67    30.6    3.83   16.7   No     
#>  8    43 Did …     12      11     38     3.6    0.129   1.24  No     
#>  9    24 Did …      3       4     19    24.4    1.36    3.28  Yes    
#> 10    36 Did …      0      13     25    19.7    2.78    2.15  No     
#> # … with 20 more rows, and 3 more variables: preddef1 <dbl>,
#> #   preddef2 <dbl>, preddef3 <dbl>

Created on 2020-03-17 by the reprex package (v0.3.0)

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