Below is small example of my txt.file that i am using in rstudio.
My objective is create a matrix whose columns representing each year ,(2012-1990) . if "gender" is woman to list the age within its respected column for that given year. Below is the code I had created but an error displays "Error in `[<-`(`*tmp*`, i, p, value = mydata[i, 1]) : subscript out of bounds" . Can someone please explain in detail my error and what may fix my code.
*******PLEASE DO NOT OFFER A COMPLETE ALTERNATIVE CODE......USE AS MUCH OF MY ORIGINAL CODE AS POSSIBLE ************
sample txt.file
age gender years
43 female 2012
36 male 2011
35 male 2010
24 female 2009
41 male 2008
47 male 2007
57 male 2006
77 male 2005
39 female 2004
70 male 2003
39 female 2002
66 male 2001
59 female 2000
66 female 1999
77 female 1998
51 male 1997
43 female 1996
41 female 1995
79 male 1994
37 female 1993
38 male 1992
53 male 1991
59 male 1990
44 male 1989
60 female 1988
51 female 1987
56 female 1986
51 female 1985
44 male 1984
61 male 1983
55 female 1982
66 male 1981
59 female 1980
62 male 1979
76 female 1978
41 female 1977
27 female 1976
52 male 1975
48 female 1974
72 female 1973
42 female 1972
48 female 1971
66 female 1970
52 female 1969
37 male 1968
52 female 1967
54 female 1966
50 male 1965
46 male 1964
62 male 1963
61 male 1962
33 male 1961
51 male 1960
59 female 1959
58 female 1958
64 male 1957
42 male 1956
32 male 1955
62 male 1954
71 female 1953
37 female 1952
61 male 1951
28 female 1950
41 female 1949
77 male 1948
34 female 1947
72 female 1946
35 male 1945
68 female 1944
67 male 1943
64 female 1942
39 male 1941
88 female 1940
40 male 1939
43 male 1938
53 male 1937
42 female 1936
38 male 1935
66 female 1934
76 female 1933
44 female 1932
43 female 1931
78 female 1930
47 female 1929
65 female 1928
74 male 1927
53 female 1926
28 female 1925
56 female 1924
82 male 1923
55 male 1922
49 female 1921
77 male 1920
84 male 1919
65 female 1918
81 female 1917
41 female 1916
45 male 1915
74 male 1914
67 male 1913
40 male 1912
71 male 1911
49 female 1910
70 female 1909
61 male 1908
60 female 1907
67 male 1906
76 male 1905
69 female 1904
31 male 1903
47 male 1902
62 male 1901
56 female 1900
66 female 2012
62 female 2011
63 female 2010
48 male 2009
64 female 2008
89 female 2007
68 female 2006
81 male 2005
74 male 2004
83 female 2003
57 female 2002
70 male 2001
79 female 2000
46 male 1999
41 male 1998
53 female 1993
setwd("C:/Users/aidan/Desktop/r-studio_practice/extracting")
mydata=read.table("genderageyear.txt", header=T)
nrow(mydata)
print(max(mydata[,3]))
print(min(mydata[,3]))
print(2012-1990)
#22 cols,1525 rows
holder=matrix(0,1525,23)
for( i in 1:1525){
p=2013-mydata[i,3]
if(mydata[i,2]=="female"){
holder[i,p]=mydata[i,1]
}
if(mydata[i,2]=="male"){
holder[i,p]=mydata[i,1]
}
}
print(holder)
#please explain your requirements in comments if this is not what you needed
setwd("C:/Users/aidan/Desktop/r-studio_practice/extracting")
mydata=read.table("genderageyear.txt", header=T)
nrow(mydata)
print(max(mydata[,3]))
print(min(mydata[,3]))
print(2012-1900)#this is 1900 not 1990
#22 cols,1525 rows
#there are 129 rows
holder=matrix(0,129,113)
for(i in 1:129){
p=2013-mydata[i,3]
if(mydata[i,2]=="female"){
holder[i,p]=mydata[i,1]
}
if(mydata[i,2]=="male"){
holder[i,p]=mydata[i,1]
}
}
print(holder)
Below is small example of my txt.file that i am using in rstudio. My objective is...
Problem #1: Consider the below matrix A, which you can copy and paste directly into Matlab. The matrix contains 3 columns. The first column consists of Test #1 marks, the second column is Test # 2 marks, and the third column is final exam marks for a large linear algebra course. Each row represents a particular student.A = [36 45 75 81 59 73 77 73 73 65 72 78 65 55 83 73 57 78 84 31 60 83...
estimate the average age at which multiple sclerosis patients were diagnosed with the condition for the first time in a given city. How big should the sample be? Define your procedures for this estimate (if necessary, set your own values of unknown parameters, based on statistical theory). In Table 1 you will find all ages of this patient population. 54 58 56 48 62 59 55 56 60 52 53 61 56 56 53 37 71 62 39 61 54...
NUMBER OF PEOPLE 10.2 10.0 10.1 8.5 10.2 8.2 8 Source: United States Census. 11. In the Sanitary District of Chicago, operating engineers are hired on of a competitive civil-service examination. In 1966, there were 223 appl for 15 jobs. The exam was held on March 12; the test scores are s arranged in increasing order. The height of each bar in the histogram next page) shows the number of people with the correspondin examiners were charged with rigging the...
1. Forecast demand for Year 4. a. Explain what technique you utilized to forecast your demand. b. Explain why you chose this technique over others. Year 3 Year 1 Year 2 Actual Actual Actual Forecast Forecast Forecast Demand Demand Demand Week 1 52 57 63 55 66 77 Week 2 49 58 68 69 75 65 Week 3 47 50 58 65 80 74 Week 4 60 53 58 55 78 67 57 Week 5 49 57 64 76 77...
Use the accompanying data set on the pulse rates (in beats per minute) of males to complete parts (a) and (b) below. LOADING... Click the icon to view the pulse rates of males. a. Find the mean and standard deviation, and verify that the pulse rates have a distribution that is roughly normal. The mean of the pulse rates is 71.871.8 beats per minute. (Round to one decimal place as needed.) The standard deviation of the pulse rates is 12.212.2...
Find the mean of the following data set: 27, 28, 30, 41, 43, 44, 45, 51, 51, 53, 53, 54, 56, 56, 56, 57, 57, 58, 58, 59, 61, 62, 62, 62, 63, 64, 67, 68, 68, 68, 69, 69, 74 68 57 55.58
Find the median of the following data set: 27, 28, 30, 41, 43, 44, 45, 51, 51, 53, 53, 54, 56, 56, 56, 57, 57, 58, 58, 59, 61, 62, 62. 62. 63, 64, 67, 68, 68, 68, 69, 69, 74 68 55.58
For determining half-lives of radioactive isotopes, it is important to know what the background radiation is in a given detector over a specific period. The following data were taken in a y -ray detection experiment over 98 ten-second intervals: 58 50 57 58 64 63 54 64 59 41 43 56 60 50 46 59 54 60 59 60 67 52 65 63 55 61 68 58 63 36 42 54 58 54 40 60 64 56 61 51 48...
Problem 4: Variables that may affect Grades The data set contains a random sample of STAT 250 Final Exam Scores out of 80 points. For each individual sampled, the time (in hours per week) that the student spent participating in a GMU club or sport and working for pay outside of GMU was recorded. Values of 0 indicate the students either does not participate in a club or sport or does not work a job for pay. The goal of...
Problem 1: Confidence Interval for Percentage of B’s. The data set “STAT 250 Final Exam Scores” contains a random sample of 269 STAT 250 students’ final exam scores (maximum of 80) collected over the past two years. Answer the following questions using this data set. a) What proportion of students in our sample earned B’s on the final exam? A letter grade of B is obtained with a score of between 64 and 71 inclusive. Hint: You can do this...