Dear All,
Thanks for helping me to redress the problem.
Cheers,
Shyam Basnet
Nepal
- Original Message -
> From: arun
> To: Janesh Devkota
> Cc: R help ; shyam basnet
> Sent: Saturday, April 20, 2013 12:52 AM
> Subject: Re: [R] how to subtotal by rows
>
-
From: arun
To: Janesh Devkota
Cc: R help ; shyam basnet ; Rui
Barradas
Sent: Friday, April 19, 2013 6:25 PM
Subject: Re: [R] how to subtotal by rows
Hi Janesh,
There is a difference in output between these :
ddply(jd1,.(fid,year),colSums,na.rm=T) #especially the first two columns
# fid
3 2
#2 1996 1 4 2 6
#3 1995 2 3 8 4
#4 1996 2 7 6 7
A.K.
From: Janesh Devkota
To: shyam basnet
Cc: "r-help@R-project.org"
Sent: Friday, April 19, 2013 3:32 PM
Subject: Re: [R] how t
19953 8 4
> #4 2 19967 6 7
> A.K.
>
>
> - Original Message -
> From: Janesh Devkota
> To: shyam basnet
> Cc: "r-help@R-project.org"
> Sent: Friday, April 19, 2013 3:30 PM
> Subject: Re: [R] how to subtotal by rows
>
> H
elp@R-project.org"
Sent: Friday, April 19, 2013 3:30 PM
Subject: Re: [R] how to subtotal by rows
Hello Shyam,
This is one way to do it
jd1 <- read.table(text="
fid year rice wheat maize
1 1995 5 NA NA
1 1995 NA 3
Hello,
You don't need as.matrix(), the following will do.
aggregate(dat[, 3:5], by = list(dat$year, dat$fid), FUN = sum, na.rm = TRUE)
Rui Barradas
Em 19-04-2013 20:24, Rui Barradas escreveu:
Hello,
Try the following.
dat <- read.table(text = "
fid year rice wheat maize
1
You can also use this short command.
library(plyr)
ddply(jd1,.(fid,year),colSums,na.rm=T)
Janesh
On Fri, Apr 19, 2013 at 2:30 PM, Janesh Devkota wrote:
> Hello Shyam,
>
> This is one way to do it
>
> jd1 <- read.table(text="
> fid year rice wheat maize
> 11995 5
Hello Shyam,
This is one way to do it
jd1 <- read.table(text="
fid year rice wheat maize
11995 5NA NA
11995 NA3 NA
11995 NA NA 2
11996 4NA NA
11996
Hello,
Try the following.
dat <- read.table(text = "
fid year rice wheat maize
11995 5NA NA
11995 NA3 NA
11995 NA NA 2
11996 4NA NA
11996 NA
Dear R-users,
I have a dataset as like below, and I want to subtotal the values of rice,wheat
and maize by year for each fid.
fid year rice wheat maize
1 1995 5 NA NA
1 1995 NA 3
10 matches
Mail list logo