0

I would like to create a dataframe like these

State % religious
QLD 20
NSW 12
WA 10
TAS 8
SA 11
VIC 15
NT 22
ACT 18

I gave that code

religious <- data.frame(
  stringsAsFactors = FALSE,
  State = c("QLD", "NSW","WA","TAS","SA","VIC","NT","ACT"),
  % religious  = c( 20,12,10,8,11,15,22,18)
)

But when i gave % religious it comes error message?

1 Answers1

0

You'll need to put the irregular name in quotes and then turn off the automatic code that translates column names to valid R variables.

religious <- data.frame(
  stringsAsFactors = FALSE,
  State = c("QLD", "NSW","WA","TAS","SA","VIC","NT","ACT"),
  "% religious"  = c( 20,12,10,8,11,15,22,18),
  check.names = FALSE
)
MrFlick
  • 195,160
  • 17
  • 277
  • 295