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
• 11,360 points
412 views

1 answer to this question.

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,840 points

Related Questions In Data Analytics

+1 vote
2 answers

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

To find number of missing values for ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
876 views
0 votes
1 answer

R Error: Recommender method UCBF not implemented for data type realRatingMatrix

Kalyan, Try changing method from UBCF to POPULAR. train ...READ MORE

answered Oct 28, 2019 in Data Analytics by anonymous
• 33,030 points
827 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 3, 2018 in Data Analytics by Bharani
• 4,660 points
1,047 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 5, 2018 in Data Analytics by Kalgi
• 52,360 points
792 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,840 points
472 views
+1 vote
1 answer

How to standardize rows when cleaning data?

The goal of this step is to ...READ MORE

answered Nov 14, 2018 in Data Analytics by Maverick
• 10,840 points
535 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,449 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,840 points
410 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,840 points
1,769 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, 2019 in Data Analytics by MrBoot
• 1,190 points
1,108 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP