Unknown punch notes Day4 College 14 days

Operating data block #
# Import data set
install.packages ( 'readxl')
Library (readxl)
with getwd ()
tianmao <-read_excel ( 'E: / Desktop shortcut file storage / unknown INSTITUTE /tianmaoTV.xlsx',skip = 1)

# Can also select 'impor dataset' sit in the box,


Create a new variable #
# calculate the month's sales
tianmao [ 'total_sales'] <- tianmao $ current_price * tianmao $ month_sales_count # This will add a new variable in the last line
tianmao [c (' current_price ', ' month_sales_count ',' total_sales ')]

# Discount
tianmao $ zhekou <-tianmao $ CURRENT_PRICE / tianmao $ ORIGINAL_PRICE
tianmao $ zhekou

Dividing price #
A <-1: 10
IfElse (A == 0 %% 2, 'even number', 'odd')
tianmao [ 'price_class'] <- IfElse (tianmao CURRENT_PRICE $ <1000, 'low',
ifelse (tianmao $ current_price <= 2000 , ' medium', 'high'))
tianmao [C ( 'CURRENT_PRICE', 'price_class')]


# Rename data block
names (tianmao) # name display column
# column name change how it
names (tianmao) [. 1] <- 'Mingcheng'
View (tianmao)

# If you do not know the column names DETAILED which column
#% in% # judged% in front of a vector, the back is a vector, this can be determined element in a vector behind whether a vector foregoing, returns TRUE, or F.
Names (tianmao)% in% 'weight'
names (tianmao) [names (tianmao)% in% 'weight'] <- 'Zhongliang'
names (tianmao)

# Centralized data subset from the extracted
NewData <-tianmao [, - C (. 1:. 3)]
names (NewData)
Coll <-C ( 'Mingcheng', 'Description', 'CURRENT_PRICE')
Logical <-names (tianmao)% Coll% in
newdata1 <-tianmao [,! logical] #! subtracting the logical representation as to TRUE

View(newdata1)

Back row #
tianmao [1,]


# How to extract the desired subset of rows
tianmao $ brand == 'millet'
logical1 <-tianmao Brand == $ 'Xiaomi / millet'
logical1
Xiaomi <-tianmao [logical1,]
View (Xiaomi) ### ????

xiaomi1 <-subset (tianmao, brand == ' millet', C ( 'Mingcheng', 'Description'))
xiaomi1
View (xiaomi1)

 

Job # 4 ----------------------------------------------- ----------------------

1 #,
Library (readxl)
tianmao_2 <-read_excel ( 'E: / desktop shortcut file storage / unknown 1 = School /tianmaoTV.xlsx',skip)
View (tianmao_2)


#2、
logical2<-tianmao_2$current_price<1000

xiaoyuyiqian <-tianmao [logical2,]
View (xiaoyuyiqian)

. 3 #,
tianmao_2 [ 'stock_class'] <- IfElse (tianmao_2 $ Stock <0,' not available ',
IfElse (tianmao_2 $ Stock <100,' low inventory "," high inventory "))
View (tianmao_2)

#4
coll1<-c('stock','stock_class')
logical3<-names(tianmao_2)%in%coll1
logical3
tiqu<-tianmao_2[,logical3]
tiqu


#5
coll2<-c('shop_id','shop_name')

logical4<-names(tianmao_2)%in%coll2
newdata3<-tianmao_2[,!logical4]
View(newdata3)

 

Guess you like

Origin www.cnblogs.com/chayibaishanlqy/p/11574852.html