s-news
[Top] [All Lists]

Re: Manipulated imported data from the command window

To: Liz von Moos <lizvonmoos@gmail.com>
Subject: Re: Manipulated imported data from the command window
From: Jourdan Gold <jgold@uoguelph.ca>
Date: Sat, 10 Jan 2009 20:04:03 -0500 (EST)
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <5B833E900330354F9FDA984D06F924280547EA15@ca-exchange.corp.pharsight.com>
here is a simple example that might help you with your problem. I have created 
a two column example with three numbers in each column. 

x1 <- c(3, 3, 2)
> x2 <- c(6, 3, 0)
> liztest <- cbind(x1, x2)
> liztest
     x1 x2 
[1,]  3  6
[2,]  3  3
[3,]  2  0
> liztest2 <- c(liztest[, 1], liztest[, 2]
+ )

> liztest2
[1] 3 3 2 6 3 0


btw, you can read data into S-Plus using the read.table command if you want to 
use command line.

A further reccommendation is that you purchase or obtain from a libary a book 
on S-plus and R. They do help.  good luck.

regards,

Jourdan 
----- Original Message -----
From: "Samer Mouksassi" <smouksassi@Pharsight.com>
To: "Liz von Moos" <lizvonmoos@gmail.com>, "Jourdan Gold" <jgold@uoguelph.ca>
Cc: s-news@lists.biostat.wustl.edu
Sent: Saturday, January 10, 2009 7:43:24 PM GMT -05:00 US/Canada Eastern
Subject: Re: [S] Manipulated imported data from the command window




A Simple way is to use a matrix command specifying how many columns you want ( 
you want a vector ie. One column and if the data should be stacked by.row or 
not. 

  

Look at matrix help. 

  

matrix (mydata, ncol=1, by.row=F) 

  

Samer 

  




From: s-news-owner@lists.biostat.wustl.edu 
[mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of Liz von Moos 
Sent: Saturday, January 10, 2009 7:37 PM 
To: Jourdan Gold; s-news@lists.biostat.wustl.edu 
Subject: Re: [S] Manipulated imported data from the command window 

  

Thank you very much for your replies. I apologize that my first email was so 
vague. It seems that there are learning curves everywhere for me. 

I am also new to user groups so please correct me if I am using I am using it 
incorrectly. 

First, I am using the version 8.04 of S-Plus with a WindowsXP machine. 

I am having trouble enterring my data into a data frame in such a way that I 
can call the aov function on it. The example I am using here is from the Online 
Manual "Guide to Statistics Volume 1 found under the Help tab in S-Plus. 

This is the data table I am working with: 

        

treatment 


poison  

A       

B       

C       

D 


I       

0.31    

0.82    

0.43    

0.45 


        

0.45    

1.1     

0.45    

0.71 


        

0.46    

0.88    

0.63    

0.66 


        

0.43    

0.72    

0.76    

0.62 


II      

0.36    

0.92    

0.44    

0.56 


        

0.29    

0.61    

0.35    

1.02 


        

0.4     

0.49    

0.31    

0.71 


        

0.23    

1.24    

0.4     

0.38 


III     

0.22    

0.3     

0.23    

0.3 


        

0.21    

0.37    

0.25    

0.36 


        

0.18    

0.38    

0.24    

0.31 


        

0.23    

0.29    

0.22    

0.33 


Consequently, I create the following (as per the online manual). 



 > fnames <- list(treatment=LETTERS[1:4], 
+ poisons=c("I", "II", "III")) 
> poisons.design <- fac.design(c(4,3), fnames, rep=4) 

I understand the design and purpose of the preceeding lines. 
The manual then suggests that the data from the table given above be enterred 
using scan(): 


> serv.time <- scan() 
1: .31 .82 .43 .45 
5: .36 .92 .44 .56 
9: .22 .3 .23 .3 
13: .45 1.10 .45 .71 
17: .29 .61 .35 1.02 
21: .21 .37 .25 .36 
25: .46 .88 .63 .66 
29: .40 .49 .31 .71 
33: .18 .38 .24 .31 
37: .43 .72 .76 .62 
41: .23 1.24 .40 .38 
45: .23 .29 .22 .33 
49: 

and then the poisons data frame is created: 

> poisons.df <- data.frame(poisons.design, serv.time) 

From here, the aov fuction can be applied. 

So far so good. Here's the problem: my own data is quite a lot larger than the 
sample data set used above so enterring the data manually (using scan()) is 
impractical. I therefore import my data using the import data function from the 
file drop-down menu. Then I can look at the data in the command window (I will 
continue to use the data from the example above in order to illustrate my 
problem). 

My data now looks like this (I've called it "mydata"): 

> mydata 
     C7   C8   C9  C10 
 1 0.31 0.82 0.43 0.45 
 2 0.45 1.10 0.45 0.71 
 3 0.46 0.88 0.63 0.66 
 4 0.43 0.72 0.76 0.62 
 5 0.36 0.92 0.44 0.56 
 6 0.29 0.61 0.35 1.02 
 7 0.40 0.49 0.31 0.71 
 8 0.23 1.24 0.40 0.38 
 9 0.22 0.30 0.23 0.30 
10 0.21 0.37 0.25 0.36 
11 0.18 0.38 0.24 0.31 
12 0.23 0.29 0.22 0.3 

I then transpose columns to rows: 
> bd.tranpose(mydata) 
    X1   X2   X3   X4   X5   X6   X7   X8   X9  X10  X11  X12 
1 0.31 0.45 0.46 0.43 0.36 0.29 0.40 0.23 0.22 0.21 0.18 0.23 
2 0.82 1.10 0.88 0.72 0.92 0.61 0.49 1.24 0.30 0.37 0.38 0.29 
3 0.43 0.45 0.63 0.76 0.44 0.35 0.31 0.40 0.23 0.25 0.24 0.22 
4 0.45 0.71 0.66 0.62 0.56 1.02 0.71 0.38 0.30 0.36 0.31 0.33 

Here's the tricky part. I now need all of the data to be enterred as one long 
sequence (as the scan() call allowed me to do). That is, I would like X1 to be 
followed by X5, then X9, then X2, then X6, etc. Put another way, I would like 
my data to end up looking like *this* when I call it by it's name: 

[1] 0.31 0.82 0.43 0.45 0.36 0.92 0.44 0.56 0.22 ... etc. 

I'm stumped as to how to affect this transposition using append() or 
bd.append(). 


I can accomplish what I want to do using the data window and 
data->transform->stack in the drop-down menu but I have not been able to figure 
out how to do this using the command window. Perhaps I'm going about this 
backwards and should instead be modifying the nature of the list and design of 
the data frame? 

If I can affect the necessary transformation with this sample data, I should be 
off to the races with my own data. 

Thank you for your patience with this new S-PLUS user. I will gladly clarify 
where necessary. 


Liz 









On Fri, Jan 9, 2009 at 6:11 PM, Jourdan Gold < jgold@uoguelph.ca > wrote: 

can you send an example of the data structure. It is difficult to guess what 
you want without any commands / data or error messages. 






----- Original Message ----- 
From: "Liz von Moos" < lizvonmoos@gmail.com > 
To: s-news@lists.biostat.wustl.edu 
Sent: Friday, January 9, 2009 5:14:30 PM GMT -05:00 US/Canada Eastern 
Subject: [S] Manipulated imported data from the command window 

I'm learning how to run two-way ANOVA's with replicates. I can follow the 
examples in the online help books, which involve entering data manually with 
scan(), and I have learned how to import files using importData. However, I 
can't figure out how to run an ANOVA on any data that I import since it is not 
in the correct format. That is: I don't know how to import a table containing 
data (from the command window) and then run an ANOVA on it because I don't know 
how to properly manipulate the imported data. Any help is ever so appreciated. 

Liz 

 

<Prev in Thread] Current Thread [Next in Thread>