[R] Beginner Question: List value without Levels

Joshua Wiley jwiley.psych at gmail.com
Tue May 24 23:26:00 CEST 2011


Hi dabs,

Thanks for that.  Part of your problem is that the data in myVals is
not being stored as numbers, it is stored as factors.  If "," is your
decimal separator, then something like:

myVal2 <- unlist(myVal)
myVal2 <- as.numeric(levels(myVal2))[myVal2]

should convert it to numeric class data, at which point, all you need to do is:

myVal2 * data

and because R is vectorized, each element of "myVal2" will be
multiplied by each element of "data".  If "," is not a decimal
separator and indicates coordinates or something, then you will need
to handle it a little differently.

Cheers,

Josh



On Tue, May 24, 2011 at 12:31 PM, dabs <ragon016 at web.de> wrote:
> Hey Joshua,
>
> thanks for your help. Here are the dput outputs :)!
>
>>dput(myVal)
> structure(list(I = structure(1L, .Label = "4,5", class = "factor"),
>    V = structure(1L, .Label = "4,2", class = "factor"), L = structure(1L,
> .Label = "3,8", class = "factor"),
>    F = structure(1L, .Label = "2,8", class = "factor"), C = structure(1L,
> .Label = "2,5", class = "factor"),
>    M = structure(1L, .Label = "1,9", class = "factor"), A = structure(1L,
> .Label = "1,8", class = "factor"),
>    G = structure(1L, .Label = "-0,4", class = "factor"), T = structure(1L,
> .Label = "-0,7", class = "factor"),
>    W = structure(1L, .Label = "-0,9", class = "factor"), S = structure(1L,
> .Label = "-0,8", class = "factor"),
>    Y = structure(1L, .Label = "-1,3", class = "factor"), P = structure(1L,
> .Label = "-1,6", class = "factor"),
>    H = structure(1L, .Label = "-3,2", class = "factor"), Q = structure(1L,
> .Label = "-3,5", class = "factor"),
>    D = structure(1L, .Label = "-3,5", class = "factor"), N = structure(1L,
> .Label = "-3,5", class = "factor"),
>    E = structure(1L, .Label = "-3,5", class = "factor"), K = structure(1L,
> .Label = "-3,9", class = "factor"),
>    R = structure(1L, .Label = "-4,5", class = "factor")), .Names = c("I",
> "V", "L", "F", "C", "M", "A", "G", "T", "W", "S", "Y", "P", "H",
> "Q", "D", "N", "E", "K", "R"), class = "data.frame", row.names = c(NA,
> -1L))
>
>
> And
>
>
>>dput(data)
> structure(c(28L, 8L, 11L, 14L, 17L, 34L, 7L, 26L, 15L, 26L, 10L,
> 9L, 12L, 8L, 11L, 21L, 19L, 33L, 7L, 7L), .Dim = 20L, .Dimnames =
> structure(list(
>    data= c("A", "C", "D", "E", "F", "G", "H", "I", "K",
>    "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "Y")), .Names =
> "data"), class = "table")
>
>
> Cheers!
>
> dabs
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Beginner-Question-List-value-without-Levels-tp3547911p3548009.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list