Error in data.frame - object not found

I keep getting an error about one of my objects not being found. I have tried fiddling with it to fix it, but have had no luck. ERROR: object 'CompanyID' not found (more details below)

Packages:

library(AER) 
library(sandwich) 
library(car) 
library(stargazer) 
library(ggplot2)
library(standardize)
library(tidyverse)
library(dplyr)
library(lubridate)
**#Code that runs without error**
csuite <- read.csv("csuite01.csv", header=TRUE, sep=",")

csuiteexec <- data.frame(csuite$DateStartRole,csuite$DateEndRole,csuite$CompanyID,csuite$CompanyName,csuite$RoleName, csuite$Ticker, csuite$DirectorID)

# These are making a new variable in csuiteexec, not my intention
csuiteexec <- csuiteexec %>%
  mutate(DateStartRole=ifelse(csuite.DateStartRole=="N"|csuite.DateStartRole=="C", "20000101", csuite.DateStartRole)) %>%
  mutate(csuite.DateStartRole = as.Date(csuite.DateStartRole, "%Y%m%d"))

csuiteexec <- csuiteexec %>%
  mutate(DateEndRole=ifelse(csuite.DateEndRole=="N"|csuite.DateEndRole=="C", "20210701", csuite.DateEndRole)) %>%
  mutate(csuite.DateEndRole = as.Date(csuite.DateEndRole, "%Y%m%d"))

When I run this line:

example <- data.frame(CompanyID, Ticker, RoleName, StartDate, EndDate, DirectorName, DirectorID)

I get this error:
Error in data.frame(CompanyID, Ticker, RoleName, StartDate, EndDate, DirectorName, :
object 'CompanyID' not found

I am trying to have it display something that will display a table with a format to the example below (it wouldn't let me upload the example photo or file).

Example intended outcome structure

Date CompanyID Ticker    Role Name     DirectorName    DirectorID
1           1                     Fake1         CEO                   Jane Doe              3256
1           2                     fake2          COO                  Jane Smith          6785
2           3                     fake3          CEO                  Jay                           4567
3           4                     fake4          CEO                   JJ                             2345

this convoluted thing is probably best replaced by a simple use of dplyr::select()

Are you suggesting using dplyr::select(CompanyID, DirectorID, & so on...) instead of the
example <- data.frame(CompanyID, etc...) ?

Yes, and think about where the info is to come from similary when you try your example <-

You have the syntax for select wrong it has to select names out of existing dataframes. For example csuite.
I.e.
select(someframe, col1, col2)
Assuming that there is someframe which counts col1 and col2 amongst its column names

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.