Creating Crosstabs using a sparse table

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating Crosstabs using a sparse table

merrittr
Hi all

I am trying to read in a table from a survey
and get the error below


 gr12 <- read.table("gr12.csv", header=TRUE)
Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
  line 1 did not have 249 elements

how would I go about reading in a table of this data, I am trying to generate a series of crostabs after I get it in
ie Gender vs q1 q2 q3 q4...
   Religion vs q1 q2 q3...


any help would be appreciated
Reply | Threaded
Open this post in threaded view
|

Re: Creating Crosstabs using a sparse table

David Winsemius

On May 4, 2010, at 7:57 PM, merrittr wrote:

>
> Hi all
>
> I am trying to read in a table from a survey
> and get the error below
>
>
> gr12 <- read.table("gr12.csv", header=TRUE)
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,  
> na.strings,
> :
>  line 1 did not have 249 elements

You need to split this problem in sections, the first of which is  
getting your data into R. A very useful function to look at files is  
count.fields(). See what it produces with your file and also read:

http://cran.r-project.org/doc/manuals/R-data.html

... If you have missing data elements at the ends of input lines then  
perhaps fill=TRUE will be helpful.

>
> how would I go about reading in a table of this data, I am trying to
> generate a series of crostabs after I get it in
> ie Gender vs q1 q2 q3 q4...
>   Religion vs q1 q2 q3...

Solve the input problem first then table() or xtabs() as approapriate.

>
>
> any help would be appreciated
>
> --

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Creating Crosstabs using a sparse table

merrittr
Thanks David I will do that


-----Original Message-----
From: David Winsemius <[hidden email]>
To: merrittr <[hidden email]>
Cc: [hidden email]
Subject: Re: [R] Creating Crosstabs using a sparse table
Date: Wed, 5 May 2010 10:18:32 -0400
Mailer: Apple Mail (2.936)

On May 4, 2010, at 7:57 PM, merrittr wrote:

>
> Hi all
>
> I am trying to read in a table from a survey
> and get the error below
>
>
> gr12 <- read.table("gr12.csv", header=TRUE)
> Error in scan(file, what, nmax, sep, dec, quote, skip, nlines,  
> na.strings,
> :
>  line 1 did not have 249 elements

You need to split this problem in sections, the first of which is  
getting your data into R. A very useful function to look at files is  
count.fields(). See what it produces with your file and also read:

http://cran.r-project.org/doc/manuals/R-data.html

... If you have missing data elements at the ends of input lines then  
perhaps fill=TRUE will be helpful.

>
> how would I go about reading in a table of this data, I am trying to
> generate a series of crostabs after I get it in
> ie Gender vs q1 q2 q3 q4...
>   Religion vs q1 q2 q3...

Solve the input problem first then table() or xtabs() as approapriate.

>
>
> any help would be appreciated
>
> --

David Winsemius, MD
West Hartford, CT

______________________________________________
[hidden email] 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.