Re: [R] splitting a long dataframe

2012-12-26 Thread Swagath

Dear Arun,
Thanks a lot for the time and help.

Cheers,
Swagath

On 12/26/12 6:24 AM, arun wrote:

Hi,
You can do this either by:
with(data1,aggregate(y,by=list(x),function(x) x)) #2nd column is a list here
#or
  res1-split(seq(nrow(data1)),data1$x)
#or
res1-tapply(data1$y,list(data1$x),function(x) x)
res2- t(sapply(res1,`[`,1:max(sapply(res1,length
res2[cbind(c(rep(8,4),rep(9,4)),c(1:4,1:4))]-res2[cbind(c(rep(8,4),rep(9,4)),c(3,1,4,2,3,1,4,2))]
  res2
#[,1] [,2] [,3] [,4]
#0:00:0018   17   24
#0:30:0029   18   25
#1:00:003   10   19   26
#1:30:004   11   20   27
#2:00:005   12   21   28
#2:30:006   13   22   29
#3:00:007   14   23   30
#3:30:00   NA   15   NA   31
#4:00:00   NA   16   NA   32

#or
res3-do.call(rbind,lapply(res1,function(x) {if(length(x)  4) 
c(NA,x[1],NA,x[2]) else x}))
  tail(res3)
  #   [,1] [,2] [,3] [,4]
#1:30:004   11   20   27
#2:00:005   12   21   28
#2:30:006   13   22   29
#3:00:007   14   23   30
#3:30:00   NA   15   NA   31
#4:00:00   NA   16   NA   32

identical(res2,res3)
#[1] TRUE

A.K.




- Original Message -
From: Swagath swagathnavi...@gmail.com
To: r-help@r-project.org
Cc:
Sent: Tuesday, December 25, 2012 12:52 PM
Subject: [R] splitting a long dataframe

Dear all...Merry Christmas

I would like to split a long dataframe. The dataframe looks like this

x-c('0:00:00', '0:30:00', '1:00:00', '1:30:00', '2:00:00', '2:30:00', 
'3:00:00', '0:00:00', '0:30:00', '1:00:00', '1:30:00', '2:00:00', '2:30:00', 
'3:00:00', '3:30:00', '4:00:00','0:00:00', '0:30:00', '1:00:00', '1:30:00', 
'2:00:00', '2:30:00', '3:00:00', '0:00:00', '0:30:00', '1:00:00', '1:30:00', 
'2:00:00', '2:30:00', '3:00:00' , '3:30:00', '4:00:00')

y=seq(1:32)

data1=data.frame(x,y)

i want to split in such a way that the output looks like

0:00:00  1  8 17 24
0:30:00  2  9 18 25
1:00:00  3 10 19 26
1:30:00  4 11 20 27
2:00:00  5 12 21 28
2:30:00  6 13 22 29
3:00:00  7 14 23 30
3:30:00 NA 15 NA 31
4:00:00 NA 16 NA 32

any ideas or functions that i look into for doing this?
Thanks a lot for your help and time.

Cheers,
Swagath

__
R-help@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.



__
R-help@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.


[R] splitting a long dataframe

2012-12-25 Thread Swagath

Dear all...Merry Christmas

I would like to split a long dataframe. The dataframe looks like this

x-c('0:00:00', '0:30:00', '1:00:00', '1:30:00', '2:00:00', '2:30:00', 
'3:00:00', '0:00:00', '0:30:00', '1:00:00', '1:30:00', '2:00:00', 
'2:30:00', '3:00:00', '3:30:00', '4:00:00','0:00:00', '0:30:00', 
'1:00:00', '1:30:00', '2:00:00', '2:30:00', '3:00:00', '0:00:00', 
'0:30:00', '1:00:00', '1:30:00', '2:00:00', '2:30:00', '3:00:00' , 
'3:30:00', '4:00:00')


y=seq(1:32)

data1=data.frame(x,y)

i want to split in such a way that the output looks like

0:00:00  1  8 17 24
0:30:00  2  9 18 25
1:00:00  3 10 19 26
1:30:00  4 11 20 27
2:00:00  5 12 21 28
2:30:00  6 13 22 29
3:00:00  7 14 23 30
3:30:00 NA 15 NA 31
4:00:00 NA 16 NA 32

any ideas or functions that i look into for doing this?
Thanks a lot for your help and time.

Cheers,
Swagath

__
R-help@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.


[R] Latitudinal mean of values in a data frame

2012-12-11 Thread Swagath Navin

Dear all,

I have a big file containing latitude points(-10 to 80) and 
corresponding values.

Example data

Lat=c(69.48134, 69.49439, 69.50736, 69.52026, 69.52438, 69.53308, 
69.53746, 69.54365, 69.54582, 69.6884, 69.69272, 69.998, 70.00055, 
70.00106, 70.00295, 70.00308, 70.00363, 70.00427, 70.00665, 70.00906, 
70.01049, 70.01053, 70.01075, 70.01208, 70.01236, 70.01418, 70.01452, 
70.01646, 70.01983, 70.0209, 70.02298, 70.02386, 70.02533, 70.02534, 
70.02856, 70.0291, 70.02983, 70.03091, 70.03267, 70.03423)


Value=c(0.18917075, 0.18856758, 0.1877328, 0.18664664, 0.18871901, 
0.18528864, 0.18797649, 0.18999862, 0.1836383, 0.15414046, 0.18542965, 
0.13914858, 0.1654665, 0.12885736, 0.18935319, 0.1912378, 0.14910094, 
0.17590007, 0.18369354, 0.12546185, 0.16096813, 0.18851039, 0.14388486, 
0.19098477, 0.17252013, 0.12965086, 0.12256515, 0.18159349, 0.15608113, 
0.18742996, 0.13858418, 0.16865459, 0.19058037, 0.12531143, 0.19189732, 
0.12019097, 0.1790819, 0.15086053, 0.18607724,  0.13330366)


dframe=data.frame(Lat, Value)

i would like to find latitudinal mean such that my output looks like the 
below:


Lat Value
69 0.18
70 0.16

I am thankful for any ideas how to perform this or which function i 
should look into.


Thanks a lot for your time,
Cheers,
Navin

__
R-help@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.