Displaying 20 results from an estimated 80000 matches similar to: "Creating new variables"
2009 Nov 08
5
look up and Missing
HI R-Users
Assume that I have a data frame 'temp' with several variables (v1,v2,v3,v4,v5.).
v1 v2 v3 v4 v5
1 2 3 3 6
5 2 4 2 0
2 -9 5 4 3
6 2 1 3 4
1, I want to look at the entire row values of when v2 =-9
like
2 -9 5 4 3
I wrote
K<- list(if(temp$v2)==-9))
I wrote the like this but it gave me which is not correct.
2009 Oct 11
2
Random number
Hi All,
I have the matrix called 'X' with 200 rows and 12 variables. I want to
create 2 new variables (V1 and V2) based on random number generator
p1<-rnorm(200. mean=0, std=1)
p2<-rnorm(200. mean=0, std=1)
x <- cbind(x, v1=ifelse(x[,'p1'] > 0.4, 1, 0), v2=ifelse(x[,'p2'] > 0.6, 0,
1))
I found the following error message
*Error: unexpected symbol in
2017 Dec 07
4
Remove
> On Dec 6, 2017, at 4:27 PM, Ashta <sewashm at gmail.com> wrote:
>
> Thank you Ista! Worked fine.
Here's another (possibly more direct in its logic?):
DM[ !ave(DM$x, DM$GR, FUN= function(x) {!length(unique(x))==1}), ]
GR x y
5 B 25 321
6 B 25 512
7 B 25 123
8 B 25 451
--
David
> On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn <istazahn at gmail.com> wrote:
2017 Dec 09
0
Remove
Hi David, Ista and all,
I have one related question Within one group I want to keep records
conditionally.
example within
group A I want keep rows that have " x" values ranged between 15 and 30.
group B I want keep rows that have " x" values ranged between 40 and 50.
group C I want keep rows that have " x" values ranged between 60 and 75.
DM <-
2017 Dec 06
2
Remove
Hi Ashta,
There are many ways to do it. Here is one:
vars <- sapply(split(DM$x, DM$GR), var)
DM[DM$GR %in% names(vars[vars > 0]), ]
Best
Ista
On Wed, Dec 6, 2017 at 6:58 PM, Ashta <sewashm at gmail.com> wrote:
> Thank you Jeff,
>
> subset( DM, "B" != x ), this works if I know the group only.
> But if I don't know that group in this case "B", how
2017 Dec 09
2
Remove
> On Dec 8, 2017, at 4:48 PM, Ashta <sewashm at gmail.com> wrote:
>
> Hi David, Ista and all,
>
> I have one related question Within one group I want to keep records
> conditionally.
> example within
> group A I want keep rows that have " x" values ranged between 15 and 30.
> group B I want keep rows that have " x" values ranged
2017 Dec 07
0
Remove
Thank you Ista! Worked fine.
On Wed, Dec 6, 2017 at 5:59 PM, Ista Zahn <istazahn at gmail.com> wrote:
> Hi Ashta,
>
> There are many ways to do it. Here is one:
>
> vars <- sapply(split(DM$x, DM$GR), var)
> DM[DM$GR %in% names(vars[vars > 0]), ]
>
> Best
> Ista
>
> On Wed, Dec 6, 2017 at 6:58 PM, Ashta <sewashm at gmail.com> wrote:
>> Thank
2017 Dec 09
1
Remove
library(dplyr)
DM <- read.table( text='GR x y
A 25 125
A 23 135
.
.
.
)
DM %>% filter((GR == "A" & (x >= 15) & (x <= 30)) |
(GR == "B" & (x >= 40) & (x <= 50)) |
(GR == "C" & (x >= 60) & (x <= 75)))
On Fri, Dec 8, 2017 at 4:48 PM, Ashta <sewashm at gmail.com>
2017 Dec 09
0
Remove
> On Dec 8, 2017, at 6:16 PM, David Winsemius <dwinsemius at comcast.net> wrote:
>
>
>> On Dec 8, 2017, at 4:48 PM, Ashta <sewashm at gmail.com> wrote:
>>
>> Hi David, Ista and all,
>>
>> I have one related question Within one group I want to keep records
>> conditionally.
>> example within
>> group A I want keep rows that
2017 Dec 09
1
Remove
Hello,
Try the following.
keep <- list(A = c(15, 30), B = c(40, 50), C = c(60, 75))
sp <- split(DM$x, DM$GR)
inx <- unlist(lapply(seq_along(sp), function(i) keep[[i]][1] <= sp[[i]]
& sp[[i]] <= keep[[i]][2]))
DM[inx, ]
# GR x y
#1 A 25 125
#2 A 23 135
#5 B 45 321
#6 B 47 512
#9 C 61 521
#10 C 68 235
Hope this helps,
Rui Barradas
On 12/9/2017 12:48 AM, Ashta
2017 Dec 09
1
Remove
You could make numeric vectors, named by the group identifier, of the
contraints
and subscript it by group name:
> DM <- read.table( text='GR x y
+ A 25 125
+ A 23 135
+ A 14 145
+ A 35 230
+ B 45 321
+ B 47 512
+ B 53 123
+ B 55 451
+ C 61 521
+ C 68 235
+ C 85 258
+ C 80 654',header = TRUE, stringsAsFactors = FALSE)
>
> GRmin <- c(A=15, B=40, C=60)
> GRmax <-
2009 Oct 01
4
Color of graph
I am trying to plot a line graph for 3 or more regression lines
abline(m1)
abline(m2)
abline(m3)
Can I change the color of each line? if so how?
Thanks in advance
Ashta
[[alternative HTML version deleted]]
2017 Dec 06
2
Remove
subset( DM, "B" != x )
This is covered in the Introduction to R document that comes with R.
--
Sent from my phone. Please excuse my brevity.
On December 6, 2017 3:21:12 PM PST, David Winsemius <dwinsemius at comcast.net> wrote:
>
>> On Dec 6, 2017, at 3:15 PM, Ashta <sewashm at gmail.com> wrote:
>>
>> Hi all,
>> In a data set I have group(GR)
2017 Dec 06
0
Remove
Thank you Jeff,
subset( DM, "B" != x ), this works if I know the group only.
But if I don't know that group in this case "B", how do I identify
group(s) that all elements of x have the same value?
On Wed, Dec 6, 2017 at 5:48 PM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
> subset( DM, "B" != x )
>
> This is covered in the Introduction to
2017 Dec 06
0
Remove
> On Dec 6, 2017, at 3:15 PM, Ashta <sewashm at gmail.com> wrote:
>
> Hi all,
> In a data set I have group(GR) and two variables x and y. I want to
> remove a group that have the same record for the x variable in each
> row.
>
> DM <- read.table( text='GR x y
> A 25 125
> A 23 135
> A 14 145
> A 12 230
> B 25 321
> B 25 512
> B 25 123
2009 Oct 23
2
Inserting rows
Hi all,
I have the data set df with three varaibles,
x1 x2 x3
1 2 5
2 4 1
5 6 0
1 1 2
I want to insert more rows ( eg, 3 rows with value filled with zeros)
1 2 5
2 4 1
5 6 6
1 1 2
0 0 0
0 0 0
0 0 0
Can any body help me out?
Thanks
2007 Jul 18
6
Classification
Hi,
I am also a quite new user of R and would like to ask you for help:
I have a data frame where all columns are numeric variables. My aim is
to convert one columnt in factors.
Example:
MD
0.2
0.1
0.8
0.3
0.7
0.6
0.01
0.2
0.5
1
1
I want to make classes:
0-0.2 A
0.21-0.4 B
0.41-0.6 C
..... and so on
So after classification I wil get:
MD
A
A
D
B
.
.
.
and so on
Please could you give an advice
2017 Jun 14
0
reading data
You need to provide reproducible data. What does the file contain? Why
are you using 'sep=' when reading fixed format. You might be able to
attach the '.txt' to your email to help with the problem. Also you did not
state what the differences that you are seeing. So help us out here.
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?
Tell me what
2017 Dec 06
3
Remove
Hi all,
In a data set I have group(GR) and two variables x and y. I want to
remove a group that have the same record for the x variable in each
row.
DM <- read.table( text='GR x y
A 25 125
A 23 135
A 14 145
A 12 230
B 25 321
B 25 512
B 25 123
B 25 451
C 11 521
C 14 235
C 15 258
C 10 654',header = TRUE, stringsAsFactors = FALSE)
In this example the output should contain group A and
2009 Oct 06
3
Plot
Hi All,
Days <- matrix(c("Monday", "Tuesday", "Wed", "Thu", "Fri", "Sat",
"Sun"),7,1)
Hum <-matrix(c(56,57,60,75,62,67,70),
Temp<-matrix(c(76,77,81,95,82,77,83),
Using the above information I want plot humidity and temperature on Y-axis
and days on X-axis
Any help is appreciated!
[[alternative HTML version