[R] Count cell Count by her frequency
David L Carlson
dcarlson at tamu.edu
Mon Dec 10 16:43:56 CET 2012
You request is not completely clear. I am assuming you want to count the
number of different characters in B for each category in A:
> A <- c("10-1", "10-1", "10-1", "10-2", "10-3")
> B <- c("aaa", "bbb", "abc", "vvv", "ggg")
> dta <- data.frame(A, B)
> dta
A B
1 10-1 aaa
2 10-1 bbb
3 10-1 abc
4 10-2 vvv
5 10-3 ggg
> a1 <- tapply(dta$B, dta$A, paste0, collapse="")
> a2 <- strsplit(a1, "")
> a3 <- lapply(a2, unique)
> a4 <- sapply(a3, length)
> dtanew <- data.frame(A=names(a4), B=a4, row.names=1:length(a4))
> dtanew
A B
1 10-1 3
2 10-2 1
3 10-3 1
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Mat
> Sent: Monday, December 10, 2012 2:50 AM
> To: r-help at r-project.org
> Subject: [R] Count cell Count by her frequency
>
> Hello togehter, i have a data.frame, with value like this:
>
> A B
> 1 10-1 aaa
> 2 10-1 bbb
> 3 10-1 abc
> 4 10-2 vvv
> 5 10-3 ggg
>
> I want now a evaluation, which character is how often in my data.frame.
> Like
> this one:
> A B
> 1 10-1 3
> 2 10-2 1
> 3 10-3 1
>
> How can i do this?
>
> Thank you.
>
> Mat
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Count-cell-
> Count-by-her-frequency-tp4652650.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.
More information about the R-help
mailing list