0
  id      value
1 expsubs    29
2 expsubs    32
3 expsubs    27
4 expsubs    36
5 expsubs    29
6 expsubs    24

New to R I have data that I've sorted in excel and tried to import into R

I want to sort or my data by the names that are in my "id" so that I can run an ANOVA on my data. Can't figure out how to get R to recognize my id column as the names for each value. Thanks!

digEmAll
  • 56,430
  • 9
  • 115
  • 140
  • i suggest looking into the dplyr package https://cran.rstudio.com/web/packages/dplyr/vignettes/introduction.html – zacdav Apr 23 '16 at 05:24
  • You should provide a reproducible example http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – shiny Apr 23 '16 at 06:11

2 Answers2

0

In this situation you need to use package dplyr:

tab <- data.frame(x = c("A", "B", "C", "C"), y = 1:4)
by_x <- group_by(tab, x)
by_x

This code will sort your data by x column.

neringab
  • 613
  • 1
  • 7
  • 16
0

Use order:

 df <- data.frame(id = c("B", "A", "D", "C"), y = c(6, 8, 1, 5))
 df

  id y
1  B 6
2  A 8
3  D 1
4  C 5

 df2 <- df[order(df$id), ]
 df2

  id y
2  A 8
1  B 6
4  C 5
3  D 1
Worice
  • 3,847
  • 3
  • 28
  • 49