0

I am using R and trying to combine two columns in a data frame into one column with both pieces of info. I have tried using the unite function and it has worked for me in the past, but it's giving me an error now and I'm not sure what I'm doing wrong.

unitedQualityCheck <- unite(QualityCheck, uSTAid, county, station, sep = ".", remove = FALSE, na.rm = FALSE)

QualityCheck is the name of my data, uSTAid is what I want to call the new column, the columns I want to combine are the county and station columns, and I want a period to separate the values inside the column. The head of my data is below, which shows the names of the columns are correct.

head(QualityCheck)
county RouteType station FactoredAADT HC_AADT_Future TDM_AADT_Future HC_TDM_AADT_Future   SGR   Rule3.4
     1         4     127         1500           1800            4700               4700 10.67 NA   1800

When I run this code I get an error that says, "Error in [.data.frame(x, x_vars) : undefined columns selected" What am I doing wrong with this code? It worked for different data previously, but doesn't want to work now.

Dave2e
  • 22,192
  • 18
  • 42
  • 50
  • Can you please provide some sample data with `dput(yourDataframe[1:5,])`? – Georgery Feb 20 '20 at 18:16
  • Please add a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). That way you can help others to help you! But the error tells you that it can't find the specified columns.Is it possible you misspelled the names of the columns you want to join? – dario Feb 20 '20 at 18:19
  • I can't reproduce your error with the sample above. Double check the QualityCheck dataframe and verify the capitalization and punctuation is correct for the variable names. – Dave2e Feb 20 '20 at 18:31
  • The syntax looks correct - if you can make the error reproducible with a cut-and-paste set of code that we can use to debug then that would help a lot. – cardinal40 Feb 20 '20 at 18:32
  • Have you tried without the ```na.rm = FALSE```? – Wolfgang Arnold Feb 20 '20 at 18:35

0 Answers0