Having difficulty with if then conditions


I am working on an additional health research project. I successfully converted the SPSS file to an R file as I am using R now for this project instead of SPSS. However, I am having trouble with some of the if then conditions in R and I keep receiving errors. Do you know what the code would be for the following below? I have also provided the SPSS syntax.

I tried this as an example along with other things but it was incorrect.
#Create vector quantity
quantity <- 2018

Set the is-else statement

if (quantity = 2018) {
+ print('vfa')
+ } else {
+ print('not vfa')
+ }
[1] "vfa"

Thanks so much!

"Use pcode and id for analysis. You’ll see other variables with the same info from different sources – but use these ones.
year = 2018. This keeps records in the EDI file (n=4,666). It removes the 19 records in the audit file that I don't have in the EDI file because PCCF+ couldn't geocode the postal codes.
flag="VSSO". This keeps all the audit records (n=4,589). This removes EDI records where this is no corresponding entry in the file.
visual = 1. This keeps VSSO records that have visual data. 53 records are in VSSO data without visual data.
vfa=1. This is a variable and needs to be used. It identifies EDI records valid for analysis, which is 4196 of the 4,666.
Language variable. Options are 1=new to language of instruction, 0=speak language of instruction, .=missing. There are 19 missing language status in the vfa=1 sample.
As an FYI: No missing gender in vfa sample, and 1 missing age."

The syntax in SPSS was the following.

IF (Province) year=2018.

IF (Province) p_code=p_code.
VARIABLE LABELS p_code 'Postal code'.

IF (Province) EDI_id=EDI_id.
VARIABLE LABELS EDI_id 'Postal code'.

IF (Province) flag="VSSO".
VARIABLE LABELS flag ' flag'.

IF (Province) Visual=1.
VARIABLE LABELS Visual ' Visual'.

IF (Province) vfa=1.
VARIABLE LABELS vfa 'Valid for analyses - typically developing'.

I think we need a FAQ: How to do a minimal reproducible example ( reprex ) for beginners

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here.



This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.