2015-05-01 3 views
-2

Я хочу создать логическую модель из фрейма данных.Извлечь переменные из векторов char

#''data.frame': 6532 obs. of 12 variables: 
#$ NewsDesk  : chr "Business" "Culture" "Business" "Business" ... 
#$ SectionName : chr "Crosswords/Games" "Arts" "Business Day" "Business Day" ... 
#$ SubsectionName: chr "" "" "Dealbook" "Dealbook" ... 
#$ Headline  : chr "More School Daze" "New 96-Page Murakami Work Coming in December" "Public Pension Funds Stay Mum on Corporate Expats" "Boot Camp for Bankers" ... 
#$ Snippet  : chr "A puzzle from Ethan Cooper that reminds me that a bill is due." "The Strange Library will arrive just three and a half months after Mr. Murakamis latest novel, Colorless Tsukuru Tazaki and His"| __truncated__ "Public pension funds have major stakes in American companies moving overseas to cut their tax bills. But they are saying little"| __truncated__ "As they struggle to find new business to bolster sluggish earnings, banks consider the nations 25 million veterans and service "| __truncated__ ... 
#$ Abstract  : chr "A puzzle from Ethan Cooper that reminds me that a bill is due." "The Strange Library will arrive just three and a half months after Mr. Murakamis latest novel, Colorless Tsukuru Tazaki and His"| __truncated__ "Public pension funds have major stakes in American companies moving overseas to cut their tax bills. But they are saying little"| __truncated__ "As they struggle to find new business to bolster sluggish earnings, banks consider the nations 25 million veterans and service "| __truncated__ ... 
#$ WordCount  : int 508 285 1211 1405 181 245 258 893 1077 188 ... 
#$ PubDate  : POSIXlt, format: "2014-09-01 22:00:09" "2014-09-01 21:14:07" ... 
#$ Popular  : int 1 0 0 1 1 1 0 1 1 0 ... 

В категории NewsDesk имеется 11 категорий.

 # Business Culture Foreign Magazine Metro National  OpEd Science Sports 
# 1846  1548  676  375  31  198  4  521  194  2 
#Styles Travel TStyle 
# 297  116  724 

Однако, мне просто нужно OpEd, Business, Science, Culture, TStyle создать модель в соответствии со значимостью. Я не знаю, как мне извлечь эти факторы из NewsDesk? Есть идеи по этому поводу?

+0

@Alex A: Возможно, я просто задал свой вопрос неопределенным способом. Я уже собрал корпус из заголовка и абстракции, вытащил будний день и час из PubDate. Я хочу сделать модель glm со всеми независимыми переменными, чтобы предсказать Популярность блога. Но я думаю, что существует слишком сложная или многокритериальная проблема из-за слишком большого количества коэффициентов. Поэтому я хочу извлечь некоторые уровни из NewsDesk и SectionName. –

+0

Хорошо, думаю, теперь я понимаю. То, что вам нужно сделать, это либо подмножество вашего фрейма данных, чтобы удалить эти наблюдения, либо сохранить наблюдения, но перекодировать нежелательные значения на что-то другое. –

ответ

0

Я бы сделал следующее.

set.seed(1237) 
NewDesk <- sample(c("OpEd", "Business", "Science", "Culture", "TStyle", "Foreign", 
     "Magazine", "Metro", "Sports", "Styles", "Travel"), 100, replace = T) 
df <- data.frame(Popular = sample(0:1, 100, replace = T), NewDesk = NewDesk) 
filter <- c("OpEd", "Business", "Science", "Culture", "TStyle") 

head(df[df$NewDesk %in% filter, ]) 

# Popular NewDesk 
#1  0 Culture 
#3  0  OpEd 
#4  0 Business 
#5  1 Science 
#8  1 TStyle 
#11  1 Business 

 Смежные вопросы

  • Нет связанных вопросов^_^