[R] how to find and use specific column after spliting dataframe
Hsin-Ya Lee
leeznar at yahoo.com.tw
Thu Nov 29 05:18:23 CET 2007
Dear Dallazuanna:
Thanks for your reply. It really has solved my problems.
However, I have another question. How can I do, if I need to calculate such
equation in all sub-dataframe? I try to use "A.split[]" to catch all
sub-dataframe, but it seems can not catch the columns of all sub-dataframe.
In other words, if the dataframe can split into 2 sub-dataframe, I need
calculate the equation in these 2 sub-dataframe.
x<-rep(c(1.2,6.8),4)
y<-rep(c(1, 2),4)
z<-rep(c(1,2),4)
t<-rep(c(0,1,2,3),length.out=8)
c<-rep(c(0,0.5,1,2),length.out=8)
df<-data.frame(pH=x, formulation=y, subject=z, time=t, concentration=c)
A.split<-split(df, list(df$pH ,df$formulation, df$subject) )
A.split []
Best regards,
Hsin-Ya Lee
Henrique Dallazuanna wrote:
>
> Try this:
>
> A.split[[1]]["time"]
> A.split[[1]][["concentration"]]
>
> test <- NULL
> for(i in 2:4){
> test[i] <- (A.split[[1]][["time"]][i] - A.split[[1]][["time"]][i-1]) *
> (A.split[[1]][["concentration"]][i] -
> A.split[[1]][["concentration"]][i-1])
> * 0.5
> }
>
>
> On 28/11/2007, leeznar <leeznar at yahoo.com.tw> wrote:
>>
>>
>>
>> Dear all:
>>
>>
>> I am a new R-user and I have 2 questions
>> about it.
>>
>>
>> 1) I need to find specific sub-dataframe,
>> and then use specific column to calculate.
>> For example, after splitting dataframe, I find specific the
>> sub-dataframe, such as "A.split [1]".
>> But, I don't know how to find "time" and "concentration" columns of
>> "A.split
>> [1]".
>
>> 2) The equation used to sub-dataframe is
>> (time[i]-time[i-1])*(concentration[i]- concentration[i-1])*1/2. I don't
>> know how to calculate it. How can I find the specific column and use it
>> to
>> calculate ?
>> x<-rep(c(1.2,6.8),4)
>> y<-rep(c(1, 2),4)
>> z<-rep(c(1,2),4)
>> t<-rep(c(0,1,2,3),length.out=8)
>> c<-rep(c(0,0.5,1,2),length.out=8)
>> df<-data.frame(pH=x, formulation=y,
>> subject=z, time=t, concentration=c)
>> A.split<-split(df, list(df$pH
>> ,df$formulation, df$subject) )
>> A.split [1]
>
>> Best regards,
>
>> Hsin-Ya Lee
>
>> ______________________________________________________________________________________
>> ÔõÓpÉÙÀ¬»øÐÅ£¿Ö»Òª¿´µ½À¬»øÐÅ£¬Á¢¼´°´Ï¡¸ß@ÊÇÀ¬»øÐÅ¡¹°´âo¡£
>> http://tw.promo.yahoo.com/antispam/index.html
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paran¨¢-Brasil
> 25¡ã 25' 40" S 49¡ã 16' 22" O
>
> [[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.
>
>
--
View this message in context: http://www.nabble.com/how-to-find-and-use-specific-column-after-spliting-dataframe-tf4886948.html#a14019176
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list