Click on the bar and see the number of international students of that country. Enjoy~
Inspired by the new era of data journalism (Simon Rogers's Datablog on the Guardian is a perfect example) and Paul Bradshaw's collective investigation journalism http://helpmeinvestigate.com/, I decided to pour out my gibberish thoughts here. Don't take it seriously, just look at it as afternoon brain snacks.
Tuesday, July 12, 2011
Sunday, July 10, 2011
Friday, April 1, 2011
R: recode levels (missing value) to NA
R load dataset from spss and assign value to missing value. Also in my original dataset, they have coded missing value with a meaningful -8 -9. I hate it! After marathon search in online forum of R topic, I digged out my way to recode levels. Here are the solutions:
>attach(dataset)
> summary(variable)
>table(variable)
>table(as.numeric(variable))
>levels(variable) ##if that s a numeric factor, it will have error message. command above just to have idea of how many NA and what value of level to recode.
>levels(variable) [level value assigned] <- NA
#to check
>sum(is.na(variable))
# it tells you how many are missing, or
>table(as.numeric(variable))
#or
> levels(variable)
## NA level should appear then.
Note: if type:
> variable[1:4] <- NA ## it means assign NA to the 1st to 4th row under this column(variable)
> variable[3] <- NA ## Likewise, assign NA to the 3rd row under the variable
It is little bit confusing but finally made it!
>attach(dataset)
> summary(variable)
>table(variable)
>table(as.numeric(variable))
>levels(variable) ##if that s a numeric factor, it will have error message. command above just to have idea of how many NA and what value of level to recode.
>levels(variable) [level value assigned] <- NA
#to check
>sum(is.na(variable))
# it tells you how many are missing, or
>table(as.numeric(variable))
#or
> levels(variable)
## NA level should appear then.
missing value for numeric variables:
> sum(is.na(BYSES2))
[1] 0
> BYSES2[BYSES2==-8] <- NA
> sum(is.na(BYSES2))
[1] 305
> BYSES2[BYSES2==-4] <- NA
> sum(is.na(BYSES2))
[1] 953
> describe(BYSES2)
Note: if type:
> variable[1:4] <- NA ## it means assign NA to the 1st to 4th row under this column(variable)
> variable[3] <- NA ## Likewise, assign NA to the 3rd row under the variable
It is little bit confusing but finally made it!
Wednesday, December 8, 2010
Tuesday, December 7, 2010
Sunday, November 14, 2010
Subscribe to:
Posts (Atom)