An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100507/71b6eacb/attachment.pl>
extract required data from already read data
5 messages · Mohan L, Joshua Wiley, David Winsemius
Try something like: sample[which(sample$Domain==xxx & sample$sex==FeMale), ] Hope that helps, Josh
On Thu, May 6, 2010 at 10:04 PM, Mohan L <l.mohanphy at gmail.com> wrote:
Hi all, I have data like this:
sample <- read.csv(file="sample.csv",sep=",",header=TRUE) sample
? stdate ? Domain ? ?sex age Login 1 ?01/11/09 ? ?xxx FeMale ?25 ? ? 2 2 ?01/11/09 ? ?xxx FeMale ?35 ? ? 4 3 ?01/11/09 ? ?xxx ? Male ?18 ? ?30 4 ?01/11/09 ? ?xxx ? Male ?31 ? ? 3 5 ?02/11/09 ? ?xxx ? Male ?32 ? ?11 6 ?02/11/09 ? ?xxx ? Male ?31 ? ? 1 7 ?02/11/09 ? ?xxx FeMale ?29 ? ? 1 8 ?02/11/09 ? ?xxx FeMale ?23 ? ? 5 9 ?03/11/09 ? ?xxx FeMale ?25 ? ? 9 10 03/11/09 ? ?xxx FeMale ?35 ? ? 6 11 03/11/09 ? ?xxx ? Male ?18 ? ? 3 12 03/11/09 ? ?xxx ? Male ?31 ? ? 0 13 04/11/09 ? ?xxx ? Male ?32 ? ?25 14 04/11/09 ? ?xxx ? Male ?31 ? ? 1 15 04/11/09 ? ?xxx FeMale ?29 ? ? 0 16 01/11/09 ? ?yyy FeMale ?25 ? ? 2 17 01/11/09 ? ?yyy FeMale ?35 ? ? 4 18 01/11/09 ? ?yyy ? Male ?18 ? ?30 19 01/11/09 ? ?yyy ? Male ?31 ? ? 3 20 02/11/09 ? ?yyy ? Male ?32 ? ?11 21 02/11/09 ? ?yyy ? Male ?31 ? ? 1 22 02/11/09 ? ?yyy FeMale ?29 ? ? 1 23 02/11/09 ? ?yyy FeMale ?23 ? ? 5 24 03/11/09 ? ?yyy FeMale ?25 ? ? 9 25 03/11/09 ? ?yyy FeMale ?35 ? ? 6 I have done the graph for all the data. Now I want to get data from particular Domain and Sex from above data, then I need to do the calculation , eg : # if both are true if(Domain == xxx && sex==FeMale) I need the data in another variable, like this 1 ?01/11/09 ? ?xxx FeMale ?25 ? ? 2 2 ?01/11/09 ? ?xxx FeMale ?35 ? ? 4 3 ?02/11/09 ? ?xxx FeMale ?29 ? ? 1 I have failed to achieve it . ?any help would greatly appreciated. Thanks & Rg Mohan L ? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100507/2575e8a3/attachment.pl>
On May 7, 2010, at 1:04 AM, Mohan L wrote:
Hi all, I have data like this:
sample <- read.csv(file="sample.csv",sep=",",header=TRUE) sample
stdate Domain sex age Login 1 01/11/09 xxx FeMale 25 2 2 01/11/09 xxx FeMale 35 4 3 01/11/09 xxx Male 18 30 4 01/11/09 xxx Male 31 3 5 02/11/09 xxx Male 32 11 6 02/11/09 xxx Male 31 1 7 02/11/09 xxx FeMale 29 1 8 02/11/09 xxx FeMale 23 5 9 03/11/09 xxx FeMale 25 9 10 03/11/09 xxx FeMale 35 6 11 03/11/09 xxx Male 18 3 12 03/11/09 xxx Male 31 0 13 04/11/09 xxx Male 32 25 14 04/11/09 xxx Male 31 1 15 04/11/09 xxx FeMale 29 0 16 01/11/09 yyy FeMale 25 2 17 01/11/09 yyy FeMale 35 4 18 01/11/09 yyy Male 18 30 19 01/11/09 yyy Male 31 3 20 02/11/09 yyy Male 32 11 21 02/11/09 yyy Male 31 1 22 02/11/09 yyy FeMale 29 1 23 02/11/09 yyy FeMale 23 5 24 03/11/09 yyy FeMale 25 9 25 03/11/09 yyy FeMale 35 6 I have done the graph for all the data. Now I want to get data from particular Domain and Sex from above data, then I need to do the calculation , eg :
I suspect you want to be working on an object like : subset(sample, Domain=="xxx" & sex == "Male")
# if both are true if(Domain == xxx && sex==FeMale)
The && operator will not give you what you want. It only returns a single value and is unusable for selecting subsets. Go back and read the introductory material. This is explained.
I need the data in another variable, like this 1 01/11/09 xxx FeMale 25 2 2 01/11/09 xxx FeMale 35 4 3 02/11/09 xxx FeMale 29 1 I have failed to achieve it . any help would greatly appreciated. Thanks & Rg Mohan L
David Winsemius, MD West Hartford, CT
1 day later
On Thu, May 6, 2010 at 10:47 PM, Mohan L <l.mohanphy at gmail.com> wrote:
<snip>
I am using source() to run program, like
source (sample.R)
I want to know how to pass the argument to my sample.R, some this like
source(sample.R, xxx,FeMale)
?Is it possible? any link will greatly appreciated.
I do not believe that you can pass arguments to source() that you want to be passed to some function inside of the file or connection being sourced. Perhaps turn the contents of the file you are sourcing in into a function, and then call that function from the command line and pass the arguments you want to it? Josh
Thanks & Rg Mohan L
Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/