path = "https://raw.githubusercontent.com/AlphaCurse/Math-with-Python/main/HousePrices.csv"
houseprices = read.table (file = path, header=FALSE, sep = ",")
head(houseprices)
## V1 V2 V3 V4 V5 V6 V7 V8 V9
## 1 NA price lotsize bedrooms bathrooms stories driveway recreation fullbase
## 2 1 42000 5850 3 1 2 yes no yes
## 3 2 38500 4000 2 1 1 yes no no
## 4 3 49500 3060 3 1 1 yes no no
## 5 4 60500 6650 3 1 2 yes yes no
## 6 5 61000 6360 2 1 1 yes no no
## V10 V11 V12 V13
## 1 gasheat aircon garage prefer
## 2 no no 1 no
## 3 no no 0 no
## 4 no no 0 no
## 5 no no 0 no
## 6 no no 0 no
price_mean = mean(houseprices$V2)
## Warning in mean.default(houseprices$V2): argument is not numeric or logical:
## returning NA
size_mean = mean(houseprices$V3)
## Warning in mean.default(houseprices$V3): argument is not numeric or logical:
## returning NA
room_median = median(houseprices$V4)
story_median = median(houseprices$V5)
price_mean
## [1] NA
size_mean
## [1] NA
room_median
## [1] "3"
story_median
## [1] "1"
df = data.frame(houseprices)
View(df)
names(df) = as.matrix(df[1, ])
df = df[-1, ]
df[] = lapply(df, function(x) type.convert(as.character(x)))
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
## Warning in type.convert.default(as.character(x)): 'as.is' should be specified by
## the caller; using TRUE
head(df)
## NA price lotsize bedrooms bathrooms stories driveway recreation fullbase
## 2 1 42000 5850 3 1 2 yes no yes
## 3 2 38500 4000 2 1 1 yes no no
## 4 3 49500 3060 3 1 1 yes no no
## 5 4 60500 6650 3 1 2 yes yes no
## 6 5 61000 6360 2 1 1 yes no no
## 7 6 66000 4160 3 1 1 yes yes yes
## gasheat aircon garage prefer
## 2 no no 1 no
## 3 no no 0 no
## 4 no no 0 no
## 5 no no 0 no
## 6 no no 0 no
## 7 no yes 0 no
df_price_mean = mean(df$price)
df_size_mean = mean(df$lotsize)
df_room_median = median(df$bedrooms)
df_story_median = median(df$stories)
price_mean
## [1] NA
df_price_mean
## [1] 68121.6
size_mean
## [1] NA
df_size_mean
## [1] 5150.266
room_median
## [1] "3"
df_room_median
## [1] 3
story_median
## [1] "1"
df_story_median
## [1] 2
df[df == 'yes'] <- 'Yes'
df[df == 'no'] <- 'No'
df['garage'][df['garage'] == 0] <- 'None'
head(df)
## NA price lotsize bedrooms bathrooms stories driveway recreation fullbase
## 2 1 42000 5850 3 1 2 Yes No Yes
## 3 2 38500 4000 2 1 1 Yes No No
## 4 3 49500 3060 3 1 1 Yes No No
## 5 4 60500 6650 3 1 2 Yes Yes No
## 6 5 61000 6360 2 1 1 Yes No No
## 7 6 66000 4160 3 1 1 Yes Yes Yes
## gasheat aircon garage prefer
## 2 No No 1 No
## 3 No No None No
## 4 No No None No
## 5 No No None No
## 6 No No None No
## 7 No Yes None No