Hi,
i am trying to read a .txt file, do a couple of select if statements on my
data, and then finally use the ?table function to get frequency counts on
the data. Specifically, i am looking at answering the following question:
What is the frequency of Grade 7 students in the province of Alberta who
are smokers?
I am having some problems:
1)i cannot get the column names to show up when print to screen
2)I cannot seem to skip variables properly when i choose certain other
variables
3)i cannot get the combination of Select If statements to work to produce
a different table with my new criteria
Here are the variables
PUMFID position1 length 5
PROV position 6 length 2
GRADE position 9 length 2
Y_Q10A position 33 length 1
Y_Q10A has the following 1=yes
2=no
9=skip
all the others have no skipped or missing values
Here is my code:
myfile<-("c:/test2.txt")
myVariableNames<-c("PUMFID","PROV","GRADE","Y_Q10A")
myVariableWidths<-c(5,2,2,1)
mydata<-read.fwf(
file=myfile,
width=myVariableWidths,
col.names=myVariableNames,
row.names="PUMFID",
fill=TRUE,
strip.white=TRUE)
print(mydata)
print( mydata [which(PROV=="AB" & GRADE==7 & Y_Q10A<9), ] )
Any help would be greatly appreciated!!
Thank-you,
Nat
------------------------------------------------------------------------------------------------------------------------
This communication is intended for the use of the recipient to which it is
addressed, and may
contain confidential, personal, and or privileged information. Please
contact the sender
immediately if you are not the intended recipient of this communication,
and do not copy,
distribute, or take action relying on it. Any communication received in
error, or subsequent
reply, should be deleted or destroyed.
[[alternative HTML version deleted]]
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.