[R] count different words in a field

David Winsemius dwinsemius at comcast.net
Tue Nov 2 22:42:26 CET 2010


On Nov 2, 2010, at 5:11 PM, Matevž Pavlič wrote:

> Hi all,
>
>
>
> I started to ask this in the other post, but it is off topis...so  
> here it is again.
>
>
>
> I have a data.frame (created with the helpof this mail list) that  
> looks like this :
>

? table
 > tbl <- table(c("HUMUS", "SLABO", "MALO", "SLABO"))
 > tbl[order(tbl)][1]
HUMUS
     1

Just make a function that does this to a vector and use lapply(dfrm,  
func)  on the dataframe.

-- 
David.

>
>
> 'data.frame':   22801 obs. of  15 variables:
>
> $ V1 : chr  "HUMUS" "SLABO" "MALO" "SLABO" ...
>
> $ V2 : chr  "IN" "GRANULIRAN" "PREPEREL" "VEZAN" ...
>
> $ V3 : chr  "HUMUSNA" "PE©ÈEN" "MELJAST" ",KONGLOMERAT," ...
>
> $ V4 : chr  "GLINA" "PROD" "PROD" "P0ROZEN," ...
>
> $ V5 : chr  "Z" "DO" "DO" "S" ...
>
> $ V6 : chr  "MALO" "r" "r" "PLASTMI" ...
>
> $ V7 : chr  "PODA," "=" "=" "GFs," ...
>
> $ V8 : chr  "LAHKO" "8Q" "60mm," "SIVORJAV" ...
>
> $ V9 : chr  "GNETNA," "mm," "S" "" ...
>
> $ V10: chr  "RJAVA" "S" "PRODNIKI," "" ...
>
> $ V11: chr  "" "PRODNIKI" "MALO" "" ...
>
> $ V12: chr  "" "DO" "PE©ÈEN" "" ...
>
> $ V13: chr  "" "R" "S" "" ...
>
> $ V14: chr  "" "=" "TANKIMI" "" ...
>
>
>
> Is it possible to count which word occours most often in each field  
> (V1, V2, V3, ...) and which one is the second and so on. Ideally i  
> would like to create a table for each field (V1, V2, V3, ...) with  
> the prevailing word and the number of occurancies  of that word in  
> that field (column) .
>
>
>
> Hope that explains it ok...
>
>
>
> Thank you, m
>
>
>
>
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list