R studio sends an error message when I try creating a data frame. My understanding of R is very basic, as far as I know the error message means that I typed something wrong. I've tried using other functions for creating the data frame and nothing changes, I've copied and pasted it, I've typed it bit by bit, I've restarted R. I've asked on my university forum, but we haven't found an issue yet. I really can't find the error.
This is the error message that it gives me:
Error: unexpected input in "sdg_data <- data.frame (Industry = c(""
EDIT: this is the full code
sdg_data <- data.frame(Industry = c(“Financial Services”, “Commercial Services”, “Non Profit and Services”, “Energy”, “Real Estate”, “Food and Beverage Products”, “Chemicals”, “Forest and Paper Products”, “Logistics”, “Mining”, “Tourism and Leisure”), Number of Companies = c(34, 21, 16, 11, 10, 9, 7, 1, 3, 7, NA), 3 Stars Awarded = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE), Most Common Goals = c(G8, G12, G13, G5, G1, G10, G9, G7, G17, G3,) stringsAsFactors = FALSE)
CodePudding user response:
you cant use a whitespace between the function call and the following parentheses:
# wont work:
x <- data.frame (mtcars)
# works:
x <- data.frame(mtcars)
CodePudding user response:
There a some errors in the code:
- The quotes are not recognized by R, hence the error.
sdg_data <- data.frame(Industry=c(“Financial Services”),stringsAsFactors = FALSE) #ERROR
sdg_data <- data.frame(Industry=c("Financial Services"),stringsAsFactors = FALSE) #WORKS
- Including spaces in the name of variables is problematic. Often is useful to avoid them or use a "_" instead:
sdg_data <- data.frame(Number of Companies = c(34, 21, 16, 11, 10, 9, 7, 1, 3, 7, NA), stringsAsFactors = FALSE)
Error: unexpected symbol in "sdg_data <- data.frame(Number of"
- There is also a comma right before a parenthesis right at the end of the code that should be placed after the parenthesis.