Re: [R] Problem with binding data-frames

2007-06-19 Thread Junnila, Jouni
Hi, 

Yes, I'm aware that the problem is that I have differing number of
columns in the different datasets. My question still remains. Is there
some way I can allow column numbers to be different, or is there some
other way combining these datasets?

Thanks,
-Jouni

On Mon, 18 Jun 2007, Petr Klasterecky wrote:

 Junnila, Jouni napsal(a):
 Hello,

 I'm having a problem concerning r-binding datasets.

 I have six datasets, from six different plates, and two different
days.
 I want to combine these datasets together for analysis. Datasets from

 day 2, have all the same columns than datasets from day 1. However in

 addition, there are few columns more in day 2. Thus, using rbind for 
 this, results a error, because the objects are not the same length.

 Error in paste(nmi[nii == 0L], collapse = , ) :
 object nii not found
 In addition: Warning message:
 longer object length
 is not a multiple of shorter object length in: clabs == nmi

 Hi,

 1. the error has nothing to do with differing lengths of your objects 
 - that's what the following warning is about. The error occured 
 because your indexing object 'nii' does not exist where R is looking
for it.

It's because the dataframes have differing number of columns, and that
has not been allowed for in the error message in that version of R.

 2. using rbind on dataframes is a bad practice, since the input is 
 converted to marices if possible. Use merge() instead.

Not so: rbind on data frames does no such conversion, and is not
problematic provided they have the same column names (and hence the same
number of columns).  You may have missed in ?rbind

  The functions 'cbind' and 'rbind' are S3 generic, with methods for
  data frames.  The data frame method will be used if at least one
  argument is a data frame and the rest are vectors or matrices.
...

and a later description of the data frame method for 'rbind'.


 Petr



 What I need, is to combine all the six together, and give for example

 NA-value in day 1, for those columns which can only be found in day
2.
 Is this somehow possible?

 I have several of these six-datasets groups, and only few of them are

 having this problem described above, and I cannot know in advance
which.
 With most of the groups writing
 rbind(data1,data2,data3,data4,data5,data6)
 works easily, but these few problematic groups need also to be 
 combined...
 Any help greatly appreciated!

 -Jouni

 __
 R-help@stat.math.ethz.ch 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.




-- 
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@stat.math.ethz.ch 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.


[R] Problem with binding data-frames

2007-06-18 Thread Junnila, Jouni
Hello,

I'm having a problem concerning r-binding datasets.

I have six datasets, from six different plates, and two different days.
I want to combine these datasets together for analysis. Datasets from
day 2, have all the same columns than datasets from day 1. However in
addition, there are few columns more in day 2. Thus, using rbind for
this, results a error, because the objects are not the same length. 

Error in paste(nmi[nii == 0L], collapse = , ) : 
object nii not found
In addition: Warning message:
longer object length
is not a multiple of shorter object length in: clabs == nmi 


What I need, is to combine all the six together, and give for example
NA-value in day 1, for those columns which can only be found in day 2.
Is this somehow possible?

I have several of these six-datasets groups, and only few of them are
having this problem described above, and I cannot know in advance which.
With most of the groups writing
rbind(data1,data2,data3,data4,data5,data6)
works easily, but these few problematic groups need also to be
combined... 
Any help greatly appreciated!

-Jouni

__
R-help@stat.math.ethz.ch 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.


[R] Choosing a column for analysis in a function

2007-05-31 Thread Junnila, Jouni
Hello all,

I'm having a problem concerning choosing columns from a dataset in a
function.

I'm writing a function for data input etc., which first reads the data,
and then does several data manipulation tasks. 
The function can be then used, with just giving the path of the .txt
file where the data is being held. 

These datasets consists of over 20 different analytes. Though,
statistical analyses should be made seperately analyte by analyte. So
the function needs to be able to choose a certain analyte based on what
the user of the function gives as a parameter when calling the function.
The name of the analyte user gives, is the same as a name of a column in
the data set.

The question is: how can I refer to the parameter which the user gives,
inside the function? I cannot give the name of the analyte directly
inside the function, as the same function should work for all the 20
analytes.
I'm giving some code for clarification:

datainput - function(data1,data2,data3,data4,data5,data6,analyte)
{
...
##data1-data6 being the paths of the six datasets I want to combine and
analyte being the special analyte I want to analyze and which can be
found on each of the datasets as a columnname.##
##Then:##
...
data.whole - subset(data.whole,
select=c(Sample.Name,Analyte.Values,Day,Plate))

##Is for choosing the columns needed for analysis. The Analyte should
now be the column of the analyte, the users is referring to when calling
the datainput-function. How to do it? ## 
I've tried something like
data.whole$Analyte.Values - data.whole$analyte ##(Or in quotes
analyte)
But this does not work. I've tried several other tricks also, but
cannot get it to work. Can someone help?

Thanks in advance,

Jouni

__
R-help@stat.math.ethz.ch 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.


Re: [R] Choosing a column for analysis in a function

2007-05-31 Thread Junnila, Jouni
Thank you for the tip.
I already got a tip from Steve Ellison and it works for me. I'm now
using

data.whole$Analyte.Values - data.whole[[analyte]] 

and everything goes smoothly! 
I tested also your suggestion, but got the following 
error:   attempt to apply non-function
So I'm sticking with Steve's suggestion. Thanks anyway!!

-Jouni

-Original Message-
From: Adaikalavan Ramasamy [mailto:[EMAIL PROTECTED] 
Sent: 31. toukokuuta 2007 16:57
To: Junnila, Jouni
Cc: r-help@stat.math.ethz.ch
Subject: Re: [R] Choosing a column for analysis in a function

Perhaps the use of as.character() like following might help?

  data.whole$Analyte.Values - data.whole$as.character(analyte)


Junnila, Jouni wrote:
 Hello all,
 
 I'm having a problem concerning choosing columns from a dataset in a 
 function.
 
 I'm writing a function for data input etc., which first reads the 
 data, and then does several data manipulation tasks.
 The function can be then used, with just giving the path of the .txt 
 file where the data is being held.
 
 These datasets consists of over 20 different analytes. Though, 
 statistical analyses should be made seperately analyte by analyte. So 
 the function needs to be able to choose a certain analyte based on 
 what the user of the function gives as a parameter when calling the
function.
 The name of the analyte user gives, is the same as a name of a column 
 in the data set.
 
 The question is: how can I refer to the parameter which the user 
 gives, inside the function? I cannot give the name of the analyte 
 directly inside the function, as the same function should work for all

 the 20 analytes.
 I'm giving some code for clarification:
 
 datainput - function(data1,data2,data3,data4,data5,data6,analyte)
 {
 ...
 ##data1-data6 being the paths of the six datasets I want to combine 
 and analyte being the special analyte I want to analyze and which can 
 be found on each of the datasets as a columnname.## ##Then:## ...
 data.whole - subset(data.whole,
 select=c(Sample.Name,Analyte.Values,Day,Plate))
 
 ##Is for choosing the columns needed for analysis. The Analyte 
 should now be the column of the analyte, the users is referring to 
 when calling the datainput-function. How to do it? ## I've tried 
 something like
 data.whole$Analyte.Values - data.whole$analyte ##(Or in quotes
 analyte)
 But this does not work. I've tried several other tricks also, but 
 cannot get it to work. Can someone help?
 
 Thanks in advance,
 
 Jouni
 
 __
 R-help@stat.math.ethz.ch 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.
 
 


__
R-help@stat.math.ethz.ch 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.