Displaying 20 results from an estimated 7000 matches similar to: "Replacing values without looping"
2007 Feb 16
2
missing -> nonmissing levels
Hi,
I expect this is simple but haven’t found an answer looking on the
archives...
I want to convert ‘NA’ (missing) to particular levels (nonmissing) in factor
vectors.
e.g. I know
> X <- c(1, 2, 3)
> summary(X)
Min. 1st Qu. Median Mean 3rd Qu. Max.
1.0 1.5 2.0 2.0 2.5 3.0
> X <- as.factor(X)
> summary(X)
1 2 3
1 1 1
>
2009 Oct 21
3
Missing data and LME models and diagnostic plots
Hello
Running R2.9.2 on Windows XP
I am puzzled by the performance of LME in situations where there are missing data. As I understand it, one of the strengths of this sort of model is how well it deals with missing data, yet lme requires nonmissing data.
Thus,
m1.mod1 <- lme(fixed = math_1 ~ I(year-2007.5)*TFC_,
data = long,
random =
2003 Nov 12
1
Plotting lm() attributes
Suppose you fit a linear model
> model.1 ~ lm(v1 ~ ..., data=myframe)
and v2 is some other column of myframe typically not in the model. You
will often want to try
> plot(v2, model.1$residuals)
but this will fail if there are NAs in the response v1 as
model.1$residuals has length equal to the number of nonmissing values in
v1. I suppose
> plot(v2[!is.na(v1)],
2010 Jan 04
1
log-normal overlay
Hello,
Using the following lines of code, I created the following graph:
2010 Jan 04
1
log normal overlay
Hello,
Using the following lines of code, I created the following graph:
2007 Jul 28
1
Error when using the cat function
Is the following developed in my console output a recognized bug or am I using the cat function incorrectly?
Thanks,
Stan
> ifelse(class(data[[n]])!="factor",{print("yes")},{print("no")})
[1] "yes"
[1] "yes"
> ifelse(class(data[[n]])!="factor",{cat("yes")},{cat("no")})
yesError in ans[test & !nas] <-
2007 Aug 09
2
Systematically biased count data regression model
Dear all,
I am attempting to explain patterns of arthropod family richness
(count data) using a regression model. It seems to be able to do a
pretty good job as an explanatory model (i.e. demonstrating
relationships between dependent and independent variables), but it has
systematic problems as a predictive model: It is biased high at low
observed values of family richness and biased low at
2009 Nov 26
1
{ggplot2} Adding Mean to (grouped) Boxplot.
Hi R Users,
I am using following R code to plot a "grouped boxplot". I'm hoping if I can
add MEAN to these boxplots. Data is copied below and attached as text file.
install.packages("ggplot2")
library(ggplot2)
dta<-read.table("Sample.txt",header=T)
attach(dta)
p <- ggplot(dta, aes(factor(month), nail))
p + geom_boxplot(aes(fill = factor(trt)))
Data:
month
2011 Dec 26
4
Summary tables of large datasets including character and numerical variables
Hello !
I am attempting to switch from being a long time SAS user to R, and would
really appreciate a bit of help ! The first thing I do in getting a large
dataset (thousands of obervations and hundreds of variables) is to run a SAS
command PROC CONTENTS VARNUM command - this provides me a table with the
name of each variable, its type and length; then I run a PROC MEANS - for
numerical
2004 Oct 21
0
Hmisc: Using stratified weighted means (wtd.mean) within a function
Hello list,
I have the following function which, as you can see, uses mean:
meanratings <- round(apply(stack03[,c(102:121)],2,function(x) (tapply(x ,actcode, mean, na.rm=T))), digits=1)
The above function yields the following output:
q27a q27b q27c q27d q27e q27f q27g q27h q27i q27j q27k q27l q27m q27o q27p
1 7.8 8.1 7.7 7.9 7.9 NaN NaN 8.4 7.8 7.0 7.6 NaN NaN 7.1 6.0
2
2010 Nov 12
2
Surprising behavior using seq()
Hello R-help,
I noticed the following surprising behavior when using %in% to find elements in a vector generated using seq().
# weird!!!
> c(7.7, 7.8, 7.9) %in% seq(4, 8, by=0.1)
[1] TRUE FALSE TRUE
# OK now
> c(7.7, 7.8, 7.9) %in% round(seq(4, 8, by=0.1), 1)
[1] TRUE TRUE TRUE
# wait, how is this different?
> c(7.7, 7.8, 7.9) %in% seq(7, 8, by=0.1)
[1] TRUE TRUE TRUE
Is there an
2009 Oct 25
3
Importing data from text file with mixed format
Hi,
I'm having difficulty importing my textfile that looks something like this:
#begin text file
Timepoint 1
ObjectNumber Volume SurfaceArea
1 5.3 9.7
2 4.9 8.3
3 5.0 9.1
4 3.5 7.8
Timepoint 2
ObjectNumber Volume SurfaceArea
1 5.1
2008 Mar 06
2
Help with parsing a data file
Hi All,
I need to parse data from a file, example shown below. The first two lines
can be skipped, the third line contains the column names. The next 13 lines
can be skipped. The next line "1991" is a year value, with the following 13
values data for that year. The file then repeats this format with (year, 13
lines of data for that year). I would ideally like to end up with an
2007 Jan 03
1
na.action and simultaneous regressions
Hi.
I am running regressions of several dependent variables using the same set
of independent variables. The independent variable values are complete, but
each dependent variable has some missing values for some observations; by
default, lm(y1~x) will carry out the regressions using only the observations
without missing values of y1. If I do lm(cbind(y1,y2)~x), the default will
be to use
2005 Nov 27
1
Question on KalmanSmooth
I am trying to use KalmanSmooth to smooth a time series
fitted by arima (and with missing values), but the $smooth component
of the output baffles me. Look at the following example:
testts <- arima.sim(list(ar=0.9),n=100)
testts[6:14] <- NA
testmod <- arima(testts, c(1,0,0))
testsmooth <- KalmanSmooth(testts, testmod$model)
par(mfrow=c(2,1))
plot(testsmooth$smooth,
2011 Feb 27
2
substract 2 data.frames
Hi!
I have 2 data.frames: "fish" and "popn":
>fish
xloc yloc id birth size weight energy gonad
20 15 15 54 -60 107.9 63.0 15952.9 8.0
21 15 15 32 -60 105.1 61.4 15538.8 7.8
91 4 43 96 -60 118.9 69.4 17573.2 8.8
71 32 4 64 -60 121.6 71.0 17976.0 9.0
34 2 64 20 -60 116.2 67.9 17173.0 8.6
95 6 20 58 -60 106.5
2007 Nov 13
2
group mean, minus each row's value
I used the following to assign each row the group average, where w is
the new group average variable, x is the variabale to be averaged, and
g is the nominal group indicator:
w <- ave(x,g)
Now I want to calculate the group average, but WITHOUT each row's
value of x. Is there an easy way to do this? I'm sure I'm missing
something obvious here, but for the life of me I can't
2010 Aug 17
3
Wilcoxon test and grouping factor with multiple levels
Dear R users,
I have a dataset with two variables: $esan - a grouping factor with 8
levels and $reus. I'd like to do wilcox.test on this dataset as
sugested Weiwei here:
https://stat.ethz.ch/pipermail/r-help/2007-July/136627.html. I tried
to adapt his recommendation but no succes. Can anyone help me?
Regards,
Iurie Malai, Senior Lecturer
Department of Psychology
Faculty of Psychology and
2013 Feb 15
3
datos climáticos cambio de formato
Hola!!
tengo un data.frame donde cada fila corresponde a un año y cada columna a
un mes (De enero a diciembre)
> head(valT)
V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13
1941 18.0 16.3 15.2 10.1 8.1 8.3 8.8 9.2 7.9 12.2 11.9 14.6
1942 17.2 15.9 13.6 11.6 8.7 6.2 6.4 7.2 9.7 12.0 14.1 16.7
1943 17.6 17.3 13.5 12.5 10.5 7.0 8.2 7.9 -999.9 -999.9
2011 May 04
3
SAPPLY function XXXX
Hello everyone,
I am attempting to write a function to count the number of non-missing
values of each column in a data frame using the sapply function. I have the
following code which is receiving the error message below.
> n.valid<-sapply(data1,sum(!is.na))
Error in !is.na : invalid argument type
Ultimately, I would like for this to be 1 conponent in a larger function
that will produce