Re: [R] using R to perform a word count - syntax refinement and incorrect number of dimensions error

From: jim holtman <jholtman_at_gmail.com>
Date: Fri 18 Aug 2006 - 21:08:16 EST

'wc1' is a vector and not a matrix. The reference 'wc1[,1]' is not legal:

> wc1 <-c("V3.PD", "V3.HD", "V3.LP")
> dim(wc1)
NULL
> wc1[,1]

Error in wc1[, 1] : incorrect number of dimensions
>

What is it that you are trying to do?

On 8/18/06, Bob Green <bgreen@dyson.brisnet.org.au> wrote:
> Hello,
>
> I am hoping someone can advise me regarding an error message I received and
> if needed, refine some syntax. I am wanting to calculate the word count for
> each row of a dataframe. Below, I have 3 variables ("V3.PD", "V3.HD",
> "V3.LP") which I want to obtain a word count for, by each row which
> contains these variables.
>
> Any assistance is much appreciated,
>
> Bob Green
>
> > wordcount1 <- read.csv("c:\\newstext.csv",header=T)
> > attach(wordcount1)
> > names(wordcount1)
> [1] "X" "i" "V3.PD" "V3.PG" "V3.HD" "V3.BY" "V3.SN" "V3.LP" "V3.TD"
> > wc1 <-c("V3.PD", "V3.HD", "V3.LP")
> > dim(wordcount1)
> [1] 178 9
> > nwords <- function(x){
> + res <- strsplit(as.character(x), "[ \t]+")
> + res <- lapply(res, length)
> + unlist(res)
> + }
> > sapply(wc1, nwords)
> V3.PD V3.HD V3.LP
> 1 1 1
> > sapply(paste(wc1[,1], wc1[,2]), nwords)
> Error in wc1[, 1] : incorrect number of dimensions
> > dim (wc1)
> NULL
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Fri Aug 18 21:25:03 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 18 Aug 2006 - 22:22:55 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.