an error occurred because rows do not match when trying to use lm to perform an ANOVA test

+1 vote

I have dataset like this:

LA NY MA
1 2 3
4 5 6
3 5
4

I am trying to use lm to perform an ANOVA test (to decide whether the mean number is the same in each state), and it keeps showing "an error occurred" because rows do not match. How can I fix this issue?

Nov 2, 2018 in Data Analytics by Ali
• 11,360 points
980 views

1 answer to this question.

0 votes

Maybe you could do something like this. To read the data, use the fill argument in read.table. Where text = txt, you would put your file name there.

(dat <- read.table(text = txt, header = TRUE, fill = TRUE))
#   LA NY MA
# 1  1  2  3
# 2  4  5  6
# 3  3  5 NA
# 4  4 NA NA

Then we can take the column means and create a new two column data frame.

cm <- colMeans(dat, na.rm = TRUE)
data.frame(state = names(cm), mean = unname(cm))
#   state mean
# 1    LA  3.0
# 2    NY  4.0
# 3    MA  4.5

where txt is

txt <- "LA NY MA
1 2 3
4 5 6
3 5
4"
answered Nov 2, 2018 by Maverick
• 10,840 points

Related Questions In Data Analytics

+1 vote
1 answer

"Error in eval(ei, envir) : object 'RDX2' not found" when trying to source the code in R

This is a very common issue that ...READ MORE

answered Oct 30, 2018 in Data Analytics by Maverick
• 10,840 points
5,109 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Error saying "duplicate 'row.names' are not allowed" when trying to setup my data for the mlogit-package

Take out the chid.var argument in your call to mlogit.data, ...READ MORE

answered Nov 12, 2018 in Data Analytics by Maverick
• 10,840 points
2,043 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,250 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,920 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 1,182 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,341 views
0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,840 points
1,766 views
0 votes
1 answer

Error saying "could not find function "read_html"" when trying to use read_html function

Hey @Ali, Execute the following two commands: install.packages(&l ...READ MORE

answered Nov 21, 2018 in Data Analytics by Maverick
• 10,840 points
4,719 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP