[R] Divide the data into sub data on a particular condition
    arun 
    smartpink111 at yahoo.com
       
    Sun Aug 25 04:16:35 CEST 2013
    
    
  
Hi,
Try this:
sapply(lst1,function(x) with(x,cor(CF,OSA)))
#      2231       2232       2233 
#-0.9607689 -1.0000000  0.9973233 
#or
library(plyr)
 ddply(dat1,.(BaseProd),summarize,Cor=cor(CF,OSA))
#  BaseProd        Cor
#1     2231 -0.9607689
#2     2232 -1.0000000
#3     2233  0.9973233
#or
 library(data.table)
 dt1<- data.table(dat1)
 dt1[,cor(CF,OSA),by=BaseProd]
#   BaseProd         V1
#1:     2231 -0.9607689
#2:     2232 -1.0000000
#3:     2233  0.9973233
A.K.
I forget to add one more thing...sorry for that.. 
after dividing the data, I have to find the correlation between CF 
and OSA for each base product....Please tell me now how to do this thing 
----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Saturday, August 24, 2013 11:44 AM
Subject: Re: Divide the data into sub data on a particular condition
Hi,
Use ?split()
#dat1 is the dataset:
lst1<- split(dat1,dat1$BaseProd)
lst1
#$`2231`
 # BaseProd  CF OSA
#1     2231 0.5 0.7
#2     2231 0.8 0.6
#3     2231 0.4 0.8
#
#$`2232`
 # BaseProd CF OSA
#4     2232  1   2
#5     2232  3   1
#
#$`2233`
 # BaseProd  CF OSA
#6     2233 0.9 0.5
#7     2233 0.7 0.5
#8     2233 4.0 5.0
#9     2233 5.0 7.0
lst1[[1]]
#  BaseProd  CF OSA
#1     2231 0.5 0.7
#2     2231 0.8 0.6
#3     2231 0.4 0.8
A.K.
Hi, 
I am totally new to R. I am facing the following problem: 
I have data of the following form 
BaseProd  CF  OSA 
2231            0.5   0.7 
2231            0.8   0.6 
2231            0.4   0.8 
2232            1        2 
2232            3         1 
2233            0.9     0.5 
2233            0.7    0.5 
2233           4           5 
2233           5           7 
I want to divide the data so that the data get divided on the basis of base product. 
like: 
data1 
BaseProd  CF  OSA 
2231            0.5   0.7 
2231            0.8   0.6 
2231            0.4   0.8 
data2 
BaseProd  CF  OSA 
2232            1        2 
2232            3         1 
data3 
BaseProd  CF  OSA 
2233            0.9     0.5 
2233            0.7    0.5 
2233           4           5 
2233           5           7 
Please help me ... Its very important and please reply ASAP
    
    
More information about the R-help
mailing list