Displaying 20 results from an estimated 7000 matches similar to: "Counting zeros in a matrix"
2006 May 24
5
Joining variables
Hello,
If I have two variables that are factors or characters and I want to
create a new variable that is the combination of both what function can
I use to accomplish this?
Ex.
Var1 Var2
SA100055113 19851113
And I want
NewVar
SA10005511319851113
Thanks in advance.
Cameron Guenther, Ph.D.
Associate Research Scientist
FWC/FWRI, Marine Fisheries Research
100 8th Avenue S.E.
St.
2006 May 16
3
subset
Hello everyone,
I have a large dataset (x) with some rows that have duplicate variables
that I would like to remove. I find which rows are the duplicates with
X1<-which(duplicated(x)). That gives me the rows with duplicated
variables. Now, how can I remove just those rose from the original data
frame. I think I can create a new data frame without the duplicates
using subset. I have tried:
2006 May 10
3
Unique?
Hello,
I have sample data set that looks like:
YEAR MONTH DAY CONTINUE SPL TIMEFISH
TIMEUNIT AREA COUNTY DEPTH DEPUNIT GEAR TRIPID
CONVUNIT
1992 1 26 1 SP0073928 8
H 7 25 4 NA 1000000
02163399054 161
1992 1 26 1 SP0073928 8
H 7 25 4 NA 1000000
02163399054 8
1992 1 26 2 SP0004228 8
H 7 25 4 NA 1000000
02163399054 161
1992 1 26 2 SP0004228 8
H 7 25 4 NA 1000000
02163399054 8
1992
2005 Nov 21
3
Warning message help
I am trying to great a new column of effort data from an existing vector
of gears used.
It is a simple code where
effort[Gear==300]=(DIST_TOW*7412)
effort[Gear==301]=(DIST_TOW*7412)
The code appears to work for some of the data but fails for others and
inserts a NA value
I also get this warning message
Warning message:
number of items to replace is not a multiple of replacement length
Can
2006 Oct 19
2
randomize a matrix
Hello everyone,
If I have an incidence matrix of 0 and 1's
P=[1 1 1 1 1 1
1 1 1 1 0 0
1 1 1 0 0 0
1 1 1 0 0 0
1 1 0 0 0 0]
I want to create a new uniform random matrix [a] that is filled with 0's
and 1's but constrained so that the row and column sums are the same as
in [P]. Does anyone know how to accomplish this?
Thanks in advance
Cameron Guenther, Ph.D.
2005 Oct 18
3
Repeating lines in a data frame
Hello,
I have a much larger dataset that is similar in form to:
year species length count
1998 1 150 1
1998 2 200 1
1998 3 250 2
1999 1 150 3
1999 2 200 4
1999 3 250 5
2000 1 150 1
2000 2 200 1
2000 3 250 1
2001 1 150 2
2001 2 200 3
2001
2006 May 03
4
Aggregate?
Hello,
I have a data set with a grouping variable (TRIPID) and several other
variables. TRIPID is repeated in some areas and I would like to use a
function like aggregate to sum the variable UNITS according to TRIPID.
However I would also like to retain the other variables as they are in
the data set with the new summed TRIPID.
So what I have is something like this:
YEAR MONTH DAY
2006 May 03
4
Aggregate?
Hello,
I have a data set with a grouping variable (TRIPID) and several other
variables. TRIPID is repeated in some areas and I would like to use a
function like aggregate to sum the variable UNITS according to TRIPID.
However I would also like to retain the other variables as they are in
the data set with the new summed TRIPID.
So what I have is something like this:
YEAR MONTH DAY
2006 Nov 30
3
Expression
Hi all,
I have a question about expression.
In a figure I want to include the term D*obs with the star as as
superscript and obs as subscript. I have even just tried to get the
star to be superscript.
The code I tried was
text(Dstar+7,120,expression(paste({}D,^*))), but that doesn't work and I
get a syntax error.
I can't seem to find anything in the help files that explains it.
2006 Mar 27
1
Glm poisson
Hello,
I am using the glm model with a poisson distribution. The model runs
just fine but when I try to get the null deviance for the model of the
null degrees of freedom I get the following errors:
> null.deviance(pAmeir_1)
Error: couldn't find function "null.deviance"
> df.null(pAmeir_1)
Error: couldn't find function "df.null"
When I do:
>
2006 Sep 26
1
How to "Pack" a matrix
Hello,
Suppose I have a matrix a where
a= sp1 sp2 sp3 sp4 sp5 sp6
site1 1 0 1 1 0 1
site2 1 0 1 1 0 1
site3 1 1 1 1 1 1
site4 0 1 1 1 0 1
site5 0 0 1 0 0 1
site6 0 0 1 0 1 0
And I want to pack that matrix so that the upper left corner contains
most of the ones and the bottom right corner contains most of the zeros
so that matrix b is
b= sp3 sp6 sp4 sp1 sp2 sp5
site1 1 1 1 1 0 0
site2
2006 Apr 06
1
Evaluating a function with another function
Hello all,
I hope someone can help me with this.
I have function that calculates two values based on input data. A
simple example follows:
test<-function(x,s,rangit=seq(0,10,1))
{
rangit<-rangit
y<-vector()
p<-vector()
for(i in 0:length(rangit)){
y[i]<-x+s[1]+rangit[i]
p[i]<-x+s[2]+rangit[i]
}
return(data.frame(rangit,y,p))
}
And returns the following:
rangit y p
1
2006 Sep 19
1
-Need help with function
Hello everyone,
I have a function here that I wrote but doesn't seem to work quite
right. Attached is the code. In the calib funcion under the for loop
Bt[i+2]<-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i+1] returns NA's for everything
after years 1983 and 1984. However the code works when it reads
Bt[i+2]<-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i]. I don't quite understand why
since it should be
2006 Sep 20
1
help with function
Hello everyone,
I have a function here that I wrote but doesn't seem to work quite
right. Attached is the code. In the calib funcion under the for loop
Bt[i+2]<-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i+1] returns NA's for everything
after years 1983 and 1984. However the code works when it reads
Bt[i+2]<-(1-m)*Bt[i+1]+Rt[i]*Rerr-Ct[i]. I don't quite understand why
since it should be
2005 Nov 10
2
IF/Else
Hi,
I am trying to write a for loop with if else statements to calculate
biomass density estimates for different types of sampling gear.
My code is:
bmd=for (i in 1:length(Gear)){
if (Gear==20) {bioden=Biomass/141}
else {if (Gear==23) {bioden=Biomass/68}}
else {if (Gear==160) {bioden=Biomass/4120}}
else {if (Gear==170) {bioden=Biomass/2210}}
else {if (Gear==300)
2005 Oct 25
1
file size limit for importing SAS file
Does anyone know if there is a file size limit for inputting a SAS data
set? The file size I am trying to import is 184 MB.
The code is:
>library("foreign")
>
> sashome<-"C:/Program Files/SAS Institute/SAS/V8"
> input.data<-read.ssd( file.path("G:/DATA/Cam/ECPATH/FIM"),"tbm_c",
+ sascmd=file.path(sashome,"sas.exe")
2007 Mar 05
1
Matrix/dataframe indexing
Hi all,
I am hoping someone can help me out with this:
If I have dataframe of years and ages and the first column and first row
are filled with leading values:
Df<- age1 age2 age3
Yr1 1 0.4 0.16
Yr2 1.5 0 0
Yr3 0.9 0 0
Yr4 1 0 0
Yr5 1.2 0 0
Yr6 1.4 0 0
Yr7 0.8 0 0
Yr8 0.6 0 0
Yr9 1.1 0 0
Now the rest of the cells need to be filled according to the previous
year and age
2007 Mar 02
0
Matrix looping
Hi all,
I am having a problem getting my fucntion to work correctly.
Here is my problem.
I have three ages: Nage<-c(1,2,3)
I have an weight matrix: Wt<-c( 0.04952867, 0.23808432, 0.34263880)
I have an age schedule of maturity: Mat<-c(0,1,1) where 0 is not mature,
and 1 is mature
I have a vulnerability schedule: Vul<-c(0,1,1)
I have an survivorship schedule:
2010 Oct 08
2
incorrect number of levels
I have a data set 382 rows and 63 columns. One of the columns is bay, and there are 6 bays. But, the number of levels for this factor is 7 when it should be six because there is some 'blank' level "". When I subset for the blank level "", I get 0 rows. What in my data could be causing this? Thanks.
> dim(datmtx)
[1] 382 63
> datmtx$bay
[1] TB TB
2010 Aug 16
1
R and windows server memory limit
I am running R 2.10.1 on Windows Server 03 in an effort to increase my memory limit. The memory limit on my machine is 4 gb and 8 gb on our server. However, when I run R within the server and try to increase my memory R still says I am limited to 4 gb. Any thoughts?
Thank you in advance for the help,
Luke McEachron
____________________________________________
Luke McEachron
Assistant Research