Just use a temporary variable!
## You should apply is.na() only to the numeric columns you need, not the
whole data frame
## see ?'[' for why.
vnew <- vdat[,3:5]
vnew[is.na(vnew)] <- 0
vdat$xy <- as.matrix(vnew) %*% c(2, 5, 3)
vdat
I still question whether this is wise; but that's for you to dete
how about one of the following?
vdat$xy <- 2 * (ifelse(is.na(vdat$x1), 0, vdat$x1)) + 5 *
(ifelse(is.na(vdat$x2),
0, vdat$x2)) + 3 * (ifelse(is.na(vdat$x3), 0, vdat$x3))
vdat$xy <- ifelse(is.na(as.matrix(vdat[, paste0("x", 1:3)])), 0,
as.matrix(vdat[, paste0("x", 1:3)])) %*% c(2, 5, 3)
On Sat, A
Sorry for the confusion, my sample data does not represent the
actual data set.
The range of value can be from -ve to +ve values and 0 could be a
true value of an observation. So, instead of replacing missing value
by zero, I want exclude them from the calculation.
On Sat, Apr 13, 2019 at
Looks to me like your initial request contradicts your clarification. Can you
explain this discrepancy?
On April 13, 2019 8:29:59 PM PDT, Val wrote:
>Hi Bert and Jim,
>Thank you for the suggestion.
>However, those missing values should not be replaced by 0's.
>I want exclude those missing values
Hi Bert and Jim,
Thank you for the suggestion.
However, those missing values should not be replaced by 0's.
I want exclude those missing values from the calculation and create
the index using only the non-missing values.
On Sat, Apr 13, 2019 at 10:14 PM Jim Lemon wrote:
>
> Hi Val,
> For this pa
If the NA's are really 0's, replace them with 0 before doing the
calculation. (see ?is.na).
If they are not 0's, think again about doing this as the results would
probably mislead.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
--
Hi Val,
For this particular problem, you can just replace NAs with zeros.
vdat[is.na(vdat)]<-0
vdat$xy <- 2*(vdat$x1) + 5*(vdat$x2) + 3*(vdat$x3)
vdat
obs Year x1 x2 x3 xy
1 1 2001 25 10 10 130
2 2 2001 0 15 25 150
3 3 2001 50 10 0 150
4 4 2001 20 0 60 220
Note that this is not a gen
Hi All,
I have a data frame with several columns and I want to create
another column by using the values of the other columns. My
problem is that some the row values for some columns have missing
values and I could not get the result I waned .
Here is the sample of my data and my attem
Hello,
could you please provide your thoughts on what I may be missing? gamlss models
are supposedly supported by MuMIn yet this one fails:
library(MuMIn)
#this lm runs
linearMod <- lm(Sepal.Length ~ ., data=iris)
options(na.action = "na.fail")
res <-dredge(linearMod,beta = T, evaluate = T)
co
Apologies for any cross-postings.
Just a reminder that registration is open for four quantitative methods
workshops in May of 2019. Each workshop features hands-on examples in Mplus and
R, plus lots of opportunities to discuss the analysis for your own research.
For more information and to regist
> "CB" == Christofer Bogaso writes:
CB> Hi,
CB> I am wondering if there is any way to get the full name from
as.yearmon()
CB> function. Please consider below example:
CB> library(quantmod)
CB> as.yearmon(Sys.Date())
CB> This gives: [1] "Apr 2019".
CB> How can I
On Sat, 13 Apr 2019, Christofer Bogaso wrote:
Hi,
I am wondering if there is any way to get the full name from as.yearmon()
function. Please consider below example:
library(quantmod)
as.yearmon(Sys.Date())
This gives: [1] "Apr 2019".
How can I extract the full name ie. 'April 2019'
Interna
Hi,
I am wondering if there is any way to get the full name from as.yearmon()
function. Please consider below example:
library(quantmod)
as.yearmon(Sys.Date())
This gives: [1] "Apr 2019".
How can I extract the full name ie. 'April 2019'
Appreciate your pointer. Thanks,
[[alternative H
13 matches
Mail list logo