Tidy up a multi-column table based on a single column

There's nothing obviously wrong with the code you posted — I can't easily access your data (here are some methods for sharing data that are better than a screenshot), but if I invent some similar sample data the code works as I would expect it to:

set.seed(42)

tgr <- data.frame(
  textForPos = rep(sample.int(10, size = 5), 2),
  tablePos = rep(sample(row.names(mtcars), 5), 2),
  stringsAsFactors = FALSE
)

tgr
#>    textForPos          tablePos
#> 1          10 Chrysler Imperial
#> 2           9       AMC Javelin
#> 3           3 Hornet Sportabout
#> 4           6    Toyota Corolla
#> 5           4    Ford Pantera L
#> 6          10 Chrysler Imperial
#> 7           9       AMC Javelin
#> 8           3 Hornet Sportabout
#> 9           6    Toyota Corolla
#> 10          4    Ford Pantera L

tgr[order(tgr$textForPos),]
#>    textForPos          tablePos
#> 3           3 Hornet Sportabout
#> 8           3 Hornet Sportabout
#> 5           4    Ford Pantera L
#> 10          4    Ford Pantera L
#> 4           6    Toyota Corolla
#> 9           6    Toyota Corolla
#> 2           9       AMC Javelin
#> 7           9       AMC Javelin
#> 1          10 Chrysler Imperial
#> 6          10 Chrysler Imperial

Created on 2018-07-25 by the reprex package (v0.2.0).

Can you explain in more detail what's not working for you?

You might also want to take a look at these guidelines for asking questions about R code:

5 Likes