Question

Suppose you have the following data: 189 1843 180 537 519 455 406 365 942 776...

Suppose you have the following data: 189 1843 180 537 519 455 406 365 942 776 372 163 101 249 250

Use the above data to create a 5 by 3 matrix in R with column names: AA, BB, CC; and row names: A, B, C, D, E.

Find row and column totals of the matrix in (a). Now add these row total and column total with the matrix (a), which will show as below: AA BB CC r.sum A 189 455 372 1016 B 1843 406 163 2412 C 180 365 101 646 D 537 942 249 1728 E 519 776 250 1545 c.sum 3268 2944 1135 7347

Now find the values larger than 500 in the matrix in (a) and replace them by the mean of values less than or equal to

Homework Answers

Answer #1
 x1=c(189,1843,180,537,519,455,406,365,942,776,372,163,101,249,250)
> a=matrix(x1,nrow=5,ncol=3)
> dimnames(a)=list(c("A","B","C","D","E"),c("AA","BB","CC"))
> a
    AA  BB  CC
A  189 455 372
B 1843 406 163
C  180 365 101
D  537 942 249
E  519 776 250
> c.sum=colSums(a)
> a1=rbind(a,c.sum)
> r.sum=rowSums(a1)
> a2=cbind(a1,r.sum)
> a2
        AA   BB   CC r.sum
A      189  455  372  1016
B     1843  406  163  2412
C      180  365  101   646
D      537  942  249  1728
E      519  776  250  1545
c.sum 3268 2944 1135  7347
> x=mean(c(189,455,372,406,163,180,365,101,249,250))
> replace(a2,a2<500,x)
        AA   BB   CC r.sum
A      273  273  273  1016
B     1843  273  273  2412
C      273  273  273   646
D      537  942  273  1728
E      519  776  273  1545
c.sum 3268 2944 1135  7347
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT