Hello everybody I am new on R I have some problem when i try to obtain frequency table which script do I need to write in R in order to obtain the frecuency of a value per repetition You could see my example Var. rep x I need to obtain these 201 1 1 201 the x=1 (repeat once), x=3 (repeat 3 times) 201 2 3 202 the X=1 (repeat 2 twice), the x=3 (repeat once), 201 3 3 203 the X=2 (rep 3 veces), valor 3 (rep 2veces) 201 4 3 202 1 1 How can I do on R? 202 2 1 202 3 3 202 4 5 203 1 2 203 2 2 203 3 3 203 3 3 -- View this message in context: http://r.789695.n4.nabble.com/Frequency-table-tp4101612p4101612.html Sent from the R help mailing list archive at Nabble.com.
Frequency table
3 messages · reynaldo_ns, Jess L, R. Michael Weylandt
Hi, I think you can try the function rep(). Example: # this means rep 1 once, 2 twice and 3 three times
rep(c(1,2,3), c(1,2,3))
[1] 1 2 2 3 3 3 # this means rep "A", "B", "C", until it reaches length of 10
rep(c("A","B","C"), length.out = 10)
[1] "A" "B" "C" "A" "B" "C" "A" "B" "C" "A" you can try more example by type: ?rep hope this helps~ -- View this message in context: http://r.789695.n4.nabble.com/Frequency-table-tp4101612p4102614.html Sent from the R help mailing list archive at Nabble.com.
I think something like this is what you are looking for, but to be
honest, I don't quite understand what you are looking for: can you
actually write out the desired result:
tapply(df$x, df$Var, table)
where df is the name of your data.
df <- structure(list(Var = c(201L, 201L, 201L, 201L, 202L, 202L, 202L,
202L, 203L, 203L, 203L, 203L), rep = c(1L, 2L, 3L, 4L, 1L, 2L,
3L, 4L, 1L, 2L, 3L, 3L), x = c(1L, 3L, 3L, 3L, 1L, 1L, 3L, 5L,
2L, 2L, 3L, 3L)), .Names = c("Var", "rep", "x"), class = "data.frame",
row.names = c(NA,
-12L))
Michael
On Wed, Nov 23, 2011 at 4:07 PM, reynaldo_ns <reynaldo_ns at hotmail.com> wrote:
Hello everybody I am new on R I have some problem when i try to obtain frequency table which script do I need to write in R in order to obtain the frecuency of a value per repetition You could see my example Var. ? ? ? ? ? rep ? ? ? ? ? x ? ? ? ? ? ? ?I need to obtain these 201 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 1 ? ? ? ? ? ?201 the x=1 (repeat once), x=3 (repeat 3 times) 201 ? ? ? ? ? ?2 ? ? ? ? ? ? ? 3 ? ? ? ? ? ?202 the X=1 (repeat 2 twice), the x=3 (repeat once), 201 ? ? ? ? ? ?3 ? ? ? ? ? ? ? 3 ? ? ? ? ? ?203 the X=2 (rep 3 veces), valor 3 (rep 2veces) 201 ? ? ? ? ? ?4 ? ? ? ? ? ? ? 3 202 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 1 ? ? ? ? ? ? How can I do on R? 202 ? ? ? ? ? ?2 ? ? ? ? ? ? ? 1 202 ? ? ? ? ? ?3 ? ? ? ? ? ? ? 3 202 ? ? ? ? ? ?4 ? ? ? ? ? ? ? 5 203 ? ? ? ? ? ?1 ? ? ? ? ? ? ? 2 203 ? ? ? ? ? ?2 ? ? ? ? ? ? ? 2 203 ? ? ? ? ? ?3 ? ? ? ? ? ? ? 3 203 ? ? ? ? ? ?3 ? ? ? ? ? ? ? 3 -- View this message in context: http://r.789695.n4.nabble.com/Frequency-table-tp4101612p4101612.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.