Hi all, I am trying to run my code in order to do a tabular analysis but whenever I do I get the following error message "Error in table(snsuser_tab, fives) :

all arguments must have the same length"

I attached my code below, any help would be greatly appreciated

setwd("/Users/sophiaduax/Desktop/PSCI3075")

mydata<-read.csv("pewdata_for_sd.csv")

snsuser<-na.omit(mydata$SNSUSER_W35)

poleng<-na.omit(mydata$SM10C_W35)

snsuser

length(snsuser)

snsuser_tab<-table(snsuser)

snsuser_tab

These are not the same command. If you execute `table(x)`

, the result is a table of the number of times each element of `x`

appears. If you execute `table(x,y)`

, `x`

and `y`

are supposed to be the same length and describe the same observations in the same order, and the result is a table of how many times the values in `x`

and the values in `y`

co-occur.

So the command without `fives`

should not give an error message, the command with `fives`

only makes sense if `fives`

is the same length as `snsuser`

.

What are you trying to obtain?

Im trying to do either a tabular analysis or a linear regression.

I mean, if you run `table(snsuser)`

you shouldn't get any length problem. But I'm not sure that's the result you are trying to obtain: it will be the number of occurence of each value in `snsuser`

.

If you have a set of points that can each be described with a value `x`

and a value `y`

, then you have two vectors `x`

and `y`

that are the same length, and you can run a linear regression with `lm(y ~ x)`

, or cross-tabulate them with `table(x,y)`

.

So it all boils down to what you are trying to determine. If `snsuser`

and `fives`

are two vectors that do not have the same length, they are not representing the same points and you can't cross-tabulate them or perform a linear regression on them. If your goal is to understand the relationship between `SNSUSER_W35`

and `SM10C_W35`

they are the same length, and this could be correct (depends on what they really represent).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

I added the "fives" command in an attempt to fix the length issue and it didn't work. What you recommend to do to make the data the same length?