Hi, I have been working with Program R for my stats class and I keep coming upon the same error, I have read so many sites about inputting data from a text file into R and I'm using the data to do a correspondence analysis. I feel like I have read everything and it is still not explaining why the error message keeps coming up, I have used the exact examples I have seen in articles and the same error keeps popping up: Error in sum(N) : invalid 'type' (character) of argument I have spent sooooooooooooo long trying to figure this out without success, I am sure it has to do with the fact that my rows have names in them. I have attached the text file I have been using and if you have any ideas as to how I can get R to plot the data using correspondence analysis with the column and row names that would be really helpful! Or if you could pass this email to someone who may know how to help me, that would be much appreciated. Thank you, Melissa Waldman my email: melissawaldman at gmail.com -------------- next part -------------- None Light Medium Heavy SM 4 2 3 2 JM 4 3 7 4 SE 25 10 12 4 JE 18 24 33 13 S 10 6 7 2
On Sun, 28 Nov 2010 21:29:08 -0800 Melissa Waldman <melissawaldman at gmail.com> wrote:> Hi, > > I have been working with Program R for my stats class and I keep > coming upon > the same error, I have read so many sites about inputting data from a > text > file into R and I'm using the data to do a correspondence analysis. > I feel > like I have read everything and it is still not explaining why the > error > message keeps coming up, I have used the exact examples I have seen > in > articles and the same error keeps popping up: Error in sum(N) : > invalid > 'type' (character) of argument > > I have spent sooooooooooooo long trying to figure this out without > success, > I am sure it has to do with the fact that my rows have names in them. > I > have attached the text file I have been using and if you have any > ideas as > to how I can get R to plot the data using correspondence analysis > with the > column and row names that would be really helpful! Or if you could > pass > this email to someone who may know how to help me, that would be much > appreciated. > > Thank you, > Melissa Waldman > > my email: melissawaldman at gmail.comHello Melissa, First of all, you need a descriptive subject, such as, "Cannot read tabular data in R". R-help is a high-volume (100 to 200 messages per day) and each person that can help you is a specialist in one or another area. Secondly, please include in your mail an excerpt of the relevant code you used that read the data in and produced the error.>From looking at your text file, I would delete the white space beforeNone, save the file, and use the following function to read your data into a data.frame: read.delim("smokedata.txt") This assumes you used a tab character between each field. HTH, Edwin -- Dr. Edwin Groot, postdoctoral associate AG Laux Institut fuer Biologie III Schaenzlestr. 1 79104 Freiburg, Deutschland +49 761-2032945
On 29/11/10 05:29, Melissa Waldman wrote:> Hi, > > I have been working with Program R for my stats class and I keep coming upon > the same error, I have read so many sites about inputting data from a text > file into R and I'm using the data to do a correspondence analysis. I feel > like I have read everything and it is still not explaining why the error > message keeps coming up, I have used the exact examples I have seen in > articles and the same error keeps popping up: Error in sum(N) : invalid > 'type' (character) of argument > > I have spent sooooooooooooo long trying to figure this out without success, > I am sure it has to do with the fact that my rows have names in them. I > have attached the text file I have been using and if you have any ideas as > to how I can get R to plot the data using correspondence analysis with the > column and row names that would be really helpful! Or if you could pass > this email to someone who may know how to help me, that would be much > appreciated. > > Thank you, > Melissa Waldman > >Hi Melissa, Welcome to the world of R. You didn't tell us which commands you were running that gave an error, but the error 'invalid 'type'' suggests to me you were trying to sum a variable that R thought was a character, and not a number. I would recomend you (re) read the introduction to R (http://cran.r-project.org/doc/manuals/R-intro.pdf), especially chapter 2, which deals with this. As a quick example, if you've read your file into a dataframe called foo, with columns none, light etc then doing class(foo$none) will tell you what R thinks this field is. If it is character then you can do foo$none <- as.numeric(foo$none) to tell R to treat it as numbers. Regards, Paul.
Your data seems to read in just fine, so what is the problem you are trying to solve?> x <- read.table('clipboard', sep='\t', header=TRUE) > str(x)'data.frame': 5 obs. of 5 variables: $ X : Factor w/ 5 levels "JE","JM","S",..: 5 2 4 1 3 $ None : int 4 4 25 18 10 $ Light : int 2 3 10 24 6 $ Medium: int 3 7 12 33 7 $ Heavy : int 2 4 4 13 2> summary(x)X None Light Medium Heavy JE:1 Min. : 4.0 Min. : 2 Min. : 3.0 Min. : 2 JM:1 1st Qu.: 4.0 1st Qu.: 3 1st Qu.: 7.0 1st Qu.: 2 S :1 Median :10.0 Median : 6 Median : 7.0 Median : 4 SE:1 Mean :12.2 Mean : 9 Mean :12.4 Mean : 5 SM:1 3rd Qu.:18.0 3rd Qu.:10 3rd Qu.:12.0 3rd Qu.: 4 Max. :25.0 Max. :24 Max. :33.0 Max. :13 On Mon, Nov 29, 2010 at 12:29 AM, Melissa Waldman <melissawaldman at gmail.com> wrote:> Hi, > > I have been working with Program R for my stats class and I keep coming upon > the same error, I have read so many sites about inputting data from a text > file into R and I'm using the data to do a correspondence analysis. ?I feel > like I have read everything and it is still not explaining why the error > message keeps coming up, I have used the exact examples I have seen in > articles and the same error keeps popping up: Error in sum(N) : invalid > 'type' (character) of argument > > I have spent sooooooooooooo long trying to figure this out without success, > I am sure it has to do with the fact that my rows have names in them. ?I > have attached the text file I have been using and if you have any ideas as > to how I can get R to plot the data using correspondence analysis with the > column and row names that would be really helpful! ?Or if you could pass > this email to someone who may know how to help me, that would be much > appreciated. > > Thank you, > Melissa Waldman > > my email: melissawaldman at gmail.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. > >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?