, 2013 12:52 AM
Subject: Re: [R] how to subtotal by rows
HI,
If you wanted to use colSums, may be this works:
ddply(jd1,.(fid,year),function(x) colSums(x[,-c(1,2)],na.rm=TRUE))
# fid year rice wheat maize
#1 1 1995 5 3 2
#2 1 1996 4 2 6
#3 2 1995 3 8
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
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
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
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 janesh.devk...@gmail.comwrote:
Hello Shyam,
This is one way to do it
jd1 - read.table(text=
fid year rice wheat maize
1
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
basnet shyamabc2...@yahoo.com
Cc: r-help@R-project.org r-help@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
8 4
#4 2 19967 6 7
A.K.
- Original Message -
From: Janesh Devkota janesh.devk...@gmail.com
To: shyam basnet shyamabc2...@yahoo.com
Cc: r-help@R-project.org r-help@r-project.org
Sent: Friday, April 19, 2013 3:30 PM
Subject: Re: [R] how to subtotal by rows
: Friday, April 19, 2013 3:32 PM
Subject: Re: [R] how to subtotal by rows
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 janesh.devk...@gmail.comwrote:
Hello Shyam,
This is one way to do
-
From: arun smartpink...@yahoo.com
To: Janesh Devkota janesh.devk...@gmail.com
Cc: R help r-help@r-project.org; shyam basnet shyamabc2...@yahoo.com; Rui
Barradas ruipbarra...@sapo.pt
Sent: Friday, April 19, 2013 6:25 PM
Subject: Re: [R] how to subtotal by rows
Hi Janesh
10 matches
Mail list logo