Look for certain values from not cleaned data

0 votes

I have the following dataset

seqno   rectyp  ps04
1       1   
1       1   
1       89  
1       89  
2       1       0
2       1       1
2       1   
2       90  
2       89  
3       1   
3       1   
3       1   
3       90  
3       90  
3       89      1
3       89      5
3       89      6
3       89  

I would like to do is look for values ps04==1 and rectype==1 for a certain seqno value. Once found, it will fill out the whole rows of that seqno with value 1. Expected output would be:

seqno   rectyp  ps04
1       1   
1       1   
1       89  
1       89  
2       1       1
2       1       1
2       1       1
2       90      1
2       89      1
3       1   
3       1   
3       1   
3       90  
3       90  
3       89      1
3       89      5
3       89      6
3       89  
Nov 13, 2018 in Data Analytics by Ali
• 10,290 points
14 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

First see what rows meet t$ps04==1 & t$rectyp==1. Get the seqno for those and then make i equal TRUE for all the rows that meet the condition.

> i <- t$seqno %in% t$seqno[t$ps04==1 & t$rectyp==1]
> i
 [1] FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> t$ps04[i] <- 1 # set values to 1
> t
   seqno rectyp ps04
1      1      1   NA
2      1      1   NA
3      1     89   NA
4      1     89   NA
5      2      1    1
6      2      1    1
7      2      1    1
8      2     90    1
9      2     89    1
10     3      1   NA
11     3      1   NA
12     3      1   NA
13     3     90   NA
14     3     90   NA
15     3     89    1
16     3     89    5
17     3     89    6
18     3     89   NA
answered Nov 13, 2018 by Maverick
• 10,000 points

Related Questions In Data Analytics

+1 vote
1 answer

Finding number of missing values and removing those missing values from a data-frame

This code gives the total number of ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,550 points
19 views
0 votes
1 answer

Building Random Forest on a data-set comprising of missing(NA) values

You have two options, either impute the ...READ MORE

answered Apr 2, 2018 in Data Analytics by Bharani
• 4,550 points
77 views
0 votes
2 answers

In data frame how to spilt strings into values?

You can do this using dplyr and ...READ MORE

answered Dec 4, 2018 in Data Analytics by Kalgi
• 35,800 points
22 views
0 votes
1 answer

How to remove rows with missing values (NAs) in a data frame?

You can use complete.cases in the following ...READ MORE

answered Apr 13, 2018 in Data Analytics by darklord
• 6,140 points
2,963 views
0 votes
1 answer

How to remove certain character from a vector

We can use sub to remove the * by specifying fixed = ...READ MORE

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,000 points
35 views
0 votes
1 answer
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
52 views
0 votes
1 answer

Clean a set of data using R

Try this: NCM <- c(5,1,3,2,4) Mbrand <- c(1,5,3,4,2) fac<-factor(Mbrand, levels ...READ MORE

answered Nov 13, 2018 in Data Analytics by Maverick
• 10,000 points
15 views
0 votes
1 answer

Error saying "duplicate 'row.names' are not allowed" when trying to setup my data for the mlogit-package

Take out the chid.var argument in your call to mlogit.data, ...READ MORE

answered Nov 12, 2018 in Data Analytics by Maverick
• 10,000 points
162 views
0 votes
2 answers

What are the skills required for data science?

Data Science is a platform for analyzing ...READ MORE

answered Apr 4 in Data Analytics by MrBoot
• 1,210 points
16 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.