[R] Reading data into
jim holtman
jholtman at gmail.com
Tue Oct 5 03:54:51 CEST 2010
try this:
> input <- readLines(textConnection("a 1 89 2 79 3 92
+ b 3 45 4 65"))
> closeAllConnections()
> # now parse each line to create a dataframe with each row being the score
> result <- NULL
> for (i in input){
+ x <- strsplit(i, '[[:space:]]+')[[1]]
+ x.l <- length(x)
+ result <- rbind(result,
+ data.frame(judge = paste("Judge_", rep(x[1], x.l %/% 2), sep = ''),
+ poster = as.integer(x[seq(2, x.l, 2)]),
+ score = as.integer(x[seq(3, x.l, 2)]),
+ stringsAsFactors = FALSE))
+ }
> require(reshape)
> cast(result, poster ~ judge, value = 'score')
poster Judge_a Judge_b
1 1 89 NA
2 2 79 NA
3 3 92 45
4 4 NA 65
On Mon, Oct 4, 2010 at 4:19 PM, Federman, Douglas
<Douglas.Federman at utoledo.edu> wrote:
> I have data in the following form:
>
>
>
> judge poster score poster score poster score
>
> a 1 89 2 79 3 92
>
> b 3 45 4 65
>
>
>
> and am trying to get it to the following:
>
>
>
> Poster Judge_A Judge_B Judge_C
>
> 1 89
>
> 2 79
>
> 3 92 45
>
> 4 65
>
>
>
> Any hints would be appreciated.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list