In data("PrefEmp") : data set ‘PrefEmp’ not found

Hi:
When I run data function I get a warning message that it can´t find the dataset in the CWD that I have previously set up. It seems data is trying to find the dataset from a different CWD and I don´t know why
Thanks for your help
Jesús

library(readr)
read.csv("PrefEmp.csv")
#> Warning in file(file, "rt"): no fue posible abrir el archivo 'PrefEmp.csv': No
#> such file or directory
#> Error in file(file, "rt"): no se puede abrir la conexión
PrefEmp <- read_csv("PrefEmp.csv")
#> Error: 'PrefEmp.csv' does not exist in current working directory ('C:/Users/Eloy/AppData/Local/Temp/Rtmp4Y0Ncb/reprex-472c60f14aef-next-esok').
View(PrefEmp)
#> Error in as.data.frame(x): objeto 'PrefEmp' no encontrado

setwd("C:/Users/Eloy")
getwd()
#> [1] "C:/Users/Eloy"
data("PrefEmp")
#> Warning in data("PrefEmp"): data set 'PrefEmp' not found

Created on 2022-07-03 by the reprex package (v2.0.1)

The data() function is for loading data sets from packages into your global environment. It is not applicable to a data frame that is already loaded. What are you trying to achieve with this?

Hi Andrés and thank you for your support.
I am trying to do a Multiple Correspondence Analysis and I getting messages when I run the reprex function, that the system doesn´t find the dataset, then I thought this was the root cause of the problem. I can read the dataset in R but when I try to run MCA function, there is an error that I don´t know how to work it out.

library(readr)
PrefEmp <- read_csv("PrefEmp.csv")
#> Error: 'PrefEmp.csv' does not exist in current working directory ('C:/Users/Eloy/AppData/Local/Temp/Rtmp4Y0Ncb/reprex-472c8044224-hurt-puma').
View(PrefEmp)
#> Error in as.data.frame(x): objeto 'PrefEmp' no encontrado

library(ggplot2)
library("FactoMineR")
library("factoextra")
#> Welcome! Want to learn more? See two factoextra-related books at https://goo.gl/ve3WBa

head(PrefEmp)
#> Error in head(PrefEmp): objeto 'PrefEmp' no encontrado

#I change the character variables into factors and then into numeric

PrefEmp$TV<-as.factor(PrefEmp$TV)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado
PrefEmp$Film<-as.factor(PrefEmp$Film)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado
PrefEmp$Art<-as.factor(PrefEmp$Art)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado
PrefEmp$Restaurant<-as.factor(PrefEmp$Restaurant)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado
PrefEmp$Gender<-as.factor(PrefEmp$Gender)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado
PrefEmp$Age<-as.factor(PrefEmp$Age)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado
PrefEmp$Job<-as.factor(PrefEmp$Job)
#> Error in is.factor(x): objeto 'PrefEmp' no encontrado


PrefEmp$TV<-as.numeric(PrefEmp$TV)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado
PrefEmp$Film<-as.numeric(PrefEmp$Film)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado
PrefEmp$Art<-as.numeric(PrefEmp$Art)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado
PrefEmp$Restaurant<-as.numeric(PrefEmp$Restaurant)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado
PrefEmp$Gender<-as.numeric(PrefEmp$Gender)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado
PrefEmp$Age<-as.numeric(PrefEmp$Age)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado
PrefEmp$Job<-as.numeric(PrefEmp$Job)
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado


head(PrefEmp)
#> Error in head(PrefEmp): objeto 'PrefEmp' no encontrado

#Exclude suplementary variables

PrefEmp.active<-PrefEmp[1:55,1:5]
#> Error in eval(expr, envir, enclos): objeto 'PrefEmp' no encontrado

head(PrefEmp.active)
#> Error in head(PrefEmp.active): objeto 'PrefEmp.active' no encontrado

#I am trying to do a model estimation:


res.mca<-MCA(PrefEmp.active,graph = FALSE)
#> Error in rownames(X): objeto 'PrefEmp.active' no encontrado

Created on 2022-07-03 by the reprex package (v2.0.1)

I don´t get the previous errors in r, but when I run the last chunk (res-mca<-MCA(PrefEmp.active,graph=FALSE)
I get the following error

Error in which(unlist(lapply(listModa, is.numeric))) :
argument to 'which' is not logical

Can you please share a small part of the data set in a copy-paste friendly format as explained in the reprex guide?

In short:

  1. If you have stored the data set in some R object, dput function is very handy.

  2. In case the data set is in a spreadsheet, check out the datapasta package. Take a look at this link.

I tried to send the dataset as you explain to me but with the first option I cannot find the way to do it properly and with the second one I got the following message when I try to send it.
If there is any other way to send you the file please let me know.

Excel (csv)
Thanks and sorry for the inconvenience.

No user-supplied code found … so we’ve made some up. You’re welcome!

sprintf("Happy %s!", weekdays(Sys.Date()))

It is pretty simple, after you read the csv file with this command

PrefEmp <- read.csv("PrefEmp.csv")

You simply have to run this other command, copy the console output and paste it here

dput(PrefEmp)

Another option would be to share a link to your csv file

Hi Andrés:
I send you the dataset.
Thanks again for your help

structure(list(Subject = 1:55, TV = c("Sport", "Comedy", "Drama",
"Films", "Films", "Drama", "Sport", "Nature", "Comedy", "News",
"Comedy", "Nature", "Drama", "Sport", "Drama", "Drama", "Police",
"Sport", "Films", "Nature", "Comedy", "Sport", "Drama", "Sport",
"Nature", "Comedy", "Police", "Sport", "Drama", "Comedy", "Comedy",
"Nature", "Comedy", "Drama", "Drama", "Police", "Drama", "Drama",
"Films", "Comedy", "Drama", "Drama", "Sport", "Sport", "Sport",
"Sport", "Drama", "Drama", "Comedy", "Drama", "Comedy", "Comedy",
"Drama", "Drama", "Comedy"), Film = c("SciFi", "Comedy", "Comedy",
"Action", "Documentary", "Documentary", "Comedy", "Comedy", "SciFi",
"SciFi", "Comedy", "Documentary", "CostumeDrama", "Comedy", "SciFi",
"SciFi", "Comedy", "Documentary", "Documentary", "SciFi", "Comedy",
"Comedy", "Action", "Comedy", "SciFi", "SciFi", "Action", "Documentary",
"Action", "Comedy", "Comedy", "Comedy", "Action", "SciFi", "CostumeDrama",
"Romance", "Comedy", "Action", "SciFi", "Comedy", "Action", "Documentary",
"Comedy", "Comedy", "Comedy", "Comedy", "SciFi", "Comedy", "Action",
"Action", "Comedy", "Romance", "Comedy", "Comedy", "Comedy"),
Art = c("Modern", "Landscape", "Impressionism", "Performance",
"Modern", "Performance", "Landscape", "Impressionism", "Modern",
"Impressionism", "Performance", "Modern", "Modern", "Landscape",
"Landscape", "Impressionism", "Performance", "Renaissance",
"Impressionism", "Landscape", "Performance", "Modern", "Landscape",
"Modern", "Landscape", "Landscape", "Impressionism", "Impressionism",
"Renaissance", "Impressionism", "Modern", "Landscape", "Performance",
"Impressionism", "Impressionism", "Landscape", "Renaissance",
"Performance", "Renaissance", "Impressionism", "Landscape",
"Modern", "Renaissance", "Renaissance", "Modern", "Performance",
"Impressionism", "Modern", "Landscape", "Modern", "Impressionism",
"Landscape", "Modern", "Modern", "Modern"), Restaurant = c("Italian",
"Italian", "French", "Indian", "SteakHouse", "SteakHouse",
"Pub", "Italian", "Burgers&Fries", "Pub", "Italian", "Indian",
"Italian", "Burgers&Fries", "Indian", "Italian", "French",
"Italian", "French", "Pub", "Italian", "Pub", "Pub", "Italian",
"SteakHouse", "SteakHouse", "Burgers&Fries", "Italian", "Italian",
"SteakHouse", "SteakHouse", "SteakHouse", "SteakHouse", "Indian",
"Italian", "Italian", "Italian", "Italian", "SteakHouse",
"Italian", "Italian", "Italian", "Italian", "Italian", "Burgers&Fries",
"Italian", "SteakHouse", "Indian", "Italian", "SteakHouse",
"Italian", "Pub", "Italian", "Italian", "Indian"), Gender = c("Male",
"Female", "Female", "Female", "Female", "Female", "Male",
"Male", "Male", "Male", "Female", "Male", "Female", "Male",
"Male", "Female", "Female", "Male", "Male", "Male", "Female",
"Female", "Male", "Male", "Male", "Male", "Male", "Male",
"Male", "Female", "Female", "Female", "Female", "Female",
"Female", "Female", "Male", "Female", "Male", "Female", "Female",
"Female", "Male", "Male", "Male", "Male", "Female", "Female",
"Female", "Male", "Male", "Female", "Female", "Female", "Male"
), Age = c("35 to 44", "45 to 54", "45 to 54", "45 to 54",
"35 to 44", "35 to 44", "45 to 54", "45 to 54", "35 to 44",
"55 to 64", "18 to 24", "35 to 44", "45 to 54", "35 to 44",
"45 to 54", "35 to 44", "25 to 34", "55 to 64", "45 to 54",
"55 to 64", "25 to 34", "45 to 54", "45 to 54", "45 to 54",
"45 to 54", "45 to 54", "65+", "45 to 54", "25 to 34", "45 to 54",
"35 to 44", "35 to 44", "25 to 34", "55 to 64", "35 to 44",
"45 to 54", "35 to 44", "35 to 44", "45 to 54", "25 to 34",
"35 to 44", "45 to 54", "25 to 34", "55 to 64", "25 to 34",
"45 to 54", "35 to 44", "45 to 54", "45 to 54", "45 to 54",
"55 to 64", "35 to 44", "45 to 54", "45 to 54", "45 to 54"
), Job = c("S&M", "R&D", "S&M", "R&D", "S&M", "R&D", "R&D",
"R&D", "R&D", "R&D", "R&D", "R&D", "S&M", "R&D", "R&D", "R&D",
"S&M", "R&D", "S&M", "R&D", "S&M", "R&D", "S&M", "S&M", "R&D",
"R&D", "R&D", "R&D", "R&D", "S&M", "S&M", "S&M", "R&D", "R&D",
"R&D", "R&D", "R&D", "R&D", "R&D", "S&M", "S&M", "S&M", "R&D",
"S&M", "R&D", "S&M", "R&D", "R&D", "S&M", "S&M", "R&D", "R&D",
"R&D", "S&M", "R&D")), class = "data.frame", row.names = c(NA,
-55L))

I actually know nothing about FactoMineR but it seems it doesn't like you to include id's, I hope this can help you

library(FactoMineR)
library(dplyr)

PrefEmp <- structure(list(Subject = 1:55, TV = c("Sport", "Comedy", "Drama",
                                      "Films", "Films", "Drama", "Sport", "Nature", "Comedy", "News",
                                      "Comedy", "Nature", "Drama", "Sport", "Drama", "Drama", "Police",
                                      "Sport", "Films", "Nature", "Comedy", "Sport", "Drama", "Sport",
                                      "Nature", "Comedy", "Police", "Sport", "Drama", "Comedy", "Comedy",
                                      "Nature", "Comedy", "Drama", "Drama", "Police", "Drama", "Drama",
                                      "Films", "Comedy", "Drama", "Drama", "Sport", "Sport", "Sport",
                                      "Sport", "Drama", "Drama", "Comedy", "Drama", "Comedy", "Comedy",
                                      "Drama", "Drama", "Comedy"), Film = c("SciFi", "Comedy", "Comedy",
                                                                            "Action", "Documentary", "Documentary", "Comedy", "Comedy", "SciFi",
                                                                            "SciFi", "Comedy", "Documentary", "CostumeDrama", "Comedy", "SciFi",
                                                                            "SciFi", "Comedy", "Documentary", "Documentary", "SciFi", "Comedy",
                                                                            "Comedy", "Action", "Comedy", "SciFi", "SciFi", "Action", "Documentary",
                                                                            "Action", "Comedy", "Comedy", "Comedy", "Action", "SciFi", "CostumeDrama",
                                                                            "Romance", "Comedy", "Action", "SciFi", "Comedy", "Action", "Documentary",
                                                                            "Comedy", "Comedy", "Comedy", "Comedy", "SciFi", "Comedy", "Action",
                                                                            "Action", "Comedy", "Romance", "Comedy", "Comedy", "Comedy"),
               Art = c("Modern", "Landscape", "Impressionism", "Performance",
                       "Modern", "Performance", "Landscape", "Impressionism", "Modern",
                       "Impressionism", "Performance", "Modern", "Modern", "Landscape",
                       "Landscape", "Impressionism", "Performance", "Renaissance",
                       "Impressionism", "Landscape", "Performance", "Modern", "Landscape",
                       "Modern", "Landscape", "Landscape", "Impressionism", "Impressionism",
                       "Renaissance", "Impressionism", "Modern", "Landscape", "Performance",
                       "Impressionism", "Impressionism", "Landscape", "Renaissance",
                       "Performance", "Renaissance", "Impressionism", "Landscape",
                       "Modern", "Renaissance", "Renaissance", "Modern", "Performance",
                       "Impressionism", "Modern", "Landscape", "Modern", "Impressionism",
                       "Landscape", "Modern", "Modern", "Modern"), Restaurant = c("Italian",
                                                                                  "Italian", "French", "Indian", "SteakHouse", "SteakHouse",
                                                                                  "Pub", "Italian", "Burgers&Fries", "Pub", "Italian", "Indian",
                                                                                  "Italian", "Burgers&Fries", "Indian", "Italian", "French",
                                                                                  "Italian", "French", "Pub", "Italian", "Pub", "Pub", "Italian",
                                                                                  "SteakHouse", "SteakHouse", "Burgers&Fries", "Italian", "Italian",
                                                                                  "SteakHouse", "SteakHouse", "SteakHouse", "SteakHouse", "Indian",
                                                                                  "Italian", "Italian", "Italian", "Italian", "SteakHouse",
                                                                                  "Italian", "Italian", "Italian", "Italian", "Italian", "Burgers&Fries",
                                                                                  "Italian", "SteakHouse", "Indian", "Italian", "SteakHouse",
                                                                                  "Italian", "Pub", "Italian", "Italian", "Indian"), Gender = c("Male",
                                                                                                                                                "Female", "Female", "Female", "Female", "Female", "Male",
                                                                                                                                                "Male", "Male", "Male", "Female", "Male", "Female", "Male",
                                                                                                                                                "Male", "Female", "Female", "Male", "Male", "Male", "Female",
                                                                                                                                                "Female", "Male", "Male", "Male", "Male", "Male", "Male",
                                                                                                                                                "Male", "Female", "Female", "Female", "Female", "Female",
                                                                                                                                                "Female", "Female", "Male", "Female", "Male", "Female", "Female",
                                                                                                                                                "Female", "Male", "Male", "Male", "Male", "Female", "Female",
                                                                                                                                                "Female", "Male", "Male", "Female", "Female", "Female", "Male"
                                                                                  ), Age = c("35 to 44", "45 to 54", "45 to 54", "45 to 54",
                                                                                             "35 to 44", "35 to 44", "45 to 54", "45 to 54", "35 to 44",
                                                                                             "55 to 64", "18 to 24", "35 to 44", "45 to 54", "35 to 44",
                                                                                             "45 to 54", "35 to 44", "25 to 34", "55 to 64", "45 to 54",
                                                                                             "55 to 64", "25 to 34", "45 to 54", "45 to 54", "45 to 54",
                                                                                             "45 to 54", "45 to 54", "65+", "45 to 54", "25 to 34", "45 to 54",
                                                                                             "35 to 44", "35 to 44", "25 to 34", "55 to 64", "35 to 44",
                                                                                             "45 to 54", "35 to 44", "35 to 44", "45 to 54", "25 to 34",
                                                                                             "35 to 44", "45 to 54", "25 to 34", "55 to 64", "25 to 34",
                                                                                             "45 to 54", "35 to 44", "45 to 54", "45 to 54", "45 to 54",
                                                                                             "55 to 64", "35 to 44", "45 to 54", "45 to 54", "45 to 54"
                                                                                  ), Job = c("S&M", "R&D", "S&M", "R&D", "S&M", "R&D", "R&D",
                                                                                             "R&D", "R&D", "R&D", "R&D", "R&D", "S&M", "R&D", "R&D", "R&D",
                                                                                             "S&M", "R&D", "S&M", "R&D", "S&M", "R&D", "S&M", "S&M", "R&D",
                                                                                             "R&D", "R&D", "R&D", "R&D", "S&M", "S&M", "S&M", "R&D", "R&D",
                                                                                             "R&D", "R&D", "R&D", "R&D", "R&D", "S&M", "S&M", "S&M", "R&D",
                                                                                             "S&M", "R&D", "S&M", "R&D", "R&D", "S&M", "S&M", "R&D", "R&D",
                                                                                             "R&D", "S&M", "R&D")), class = "data.frame", row.names = c(NA,
                                                                                                                                                        -55L))
PrefEmp %>% 
    mutate(across(where(is.character), as.factor)) %>% 
    select(-Subject) %>% 
    MCA()
#> Warning: ggrepel: 22 unlabeled data points (too many overlaps). Consider
#> increasing max.overlaps

#> **Results of the Multiple Correspondence Analysis (MCA)**
#> The analysis was performed on 55 individuals, described by 7 variables
#> *The results are available in the following objects:
#> 
#>    name              description                       
#> 1  "$eig"            "eigenvalues"                     
#> 2  "$var"            "results for the variables"       
#> 3  "$var$coord"      "coord. of the categories"        
#> 4  "$var$cos2"       "cos2 for the categories"         
#> 5  "$var$contrib"    "contributions of the categories" 
#> 6  "$var$v.test"     "v-test for the categories"       
#> 7  "$ind"            "results for the individuals"     
#> 8  "$ind$coord"      "coord. for the individuals"      
#> 9  "$ind$cos2"       "cos2 for the individuals"        
#> 10 "$ind$contrib"    "contributions of the individuals"
#> 11 "$call"           "intermediate results"            
#> 12 "$call$marge.col" "weights of columns"              
#> 13 "$call$marge.li"  "weights of rows"

Created on 2022-07-03 by the reprex package (v2.0.1)

Hi Andrés:

Thank you for your help.

I run the code you sent to me and Igot the following error

Error in select(., -Subject) : unused argument (-Subject)

Thanks.

I suspect you have not loaded the dplyr package, the code works with the sample data you have provided as demonstrated by the reprex I posted so if it doesn't work for you, you must be doing something different.

Hi, Andrés:
I wrote the code from scratch and now it works .The problem was that the package dplyr didn´t work properly, so I removed it and installed it again and now it works perfectly
Thanks a lot for your support
Jesús

This topic was automatically closed 21 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.