Dear group,
I have a dataframe (x). (4 rows, 3 columns for
example)
I want to create a master list (my_list) from data
frame.
I want each row of x to be a list.
I tried 3 different ways: writing a loop, using apply,
and going through each row.
Going through each row works for me. since I have 1000
rows, I cannot manually create 1000 lists and combine
them. I apologize for the long email with all 3
methods I tried. I request you to help me if I can
automate last method. thanks srini
proposal:
x <- data frame
list1 <- list(src=x[1,]$V1,
title = x[1,]$V2,
pbset = X[1]$V3)
list2 <- list(src=x[2,]$V1,
title = x[2,]$V2,
pbset = X[2]$V3)
master_list <- list(list1,list2)
Solution:
Write a for loop that takes each row and creates a
list.
Append this list to a master list.
Example:
y=list(src=as.character(x[i,src),
title=as.character(x[i,]$title),
probes=as.character(x[i,]$probesets))
mastr_list[i]=y
}
problem:
Warning messages:
1: In test[i] = y :
number of items to replace is not a multiple of
replacement length
2: In test[i] = y :
number of items to replace is not a multiple of
replacement length
3: In test[i] = y :
number of items to replace is not a multiple of
replacement length
4: In test[i] = y :
number of items to replace is not a multiple of
replacement length
mastr_list
[[1]]
[1] "positional"
[[2]]
[1] "positional"
[[3]]
[1] "positional"
[[4]]
[1] "positional"
How can I make my master list.
I tried also apply function and result is not exactly
what I desire.
master_list <- apply(x, 1, list)
master_list
[[1]]
[[1]][[1]]
title
src probesets
"chr16q"
"positional" "CMAR,USP10,PSORS8,WT3,SLI1"
[[2]]
[[2]][[1]]
title src
probesets
"chr4p" "positional"
"ATP5I,MHW1,STGD4"
[[3]]
[[3]][[1]]
title src probesets
"chr1q13" "positional" "SCARNA2"
[[4]]
[[4]][[1]]
title src probesets
"chr4q1" "positional" "MORF4LP4"
my final result should look like this:
Dear group,
I have a dataframe (x). (4 rows, 3 columns for
example)
I want to create a master list (my_list) from data
frame.
I want each row of x to be a list.
I tried 3 different ways: writing a loop, using apply,
and going through each row.
Going through each row works for me. since I have 1000
rows, I cannot manually create 1000 lists and combine
them. I apologize for the long email with all 3
methods I tried. I request you to help me if I can
automate last method. thanks srini
proposal:
x <- data frame
list1 <- list(src=x[1,]$V1,
title = x[1,]$V2,
pbset = X[1]$V3)
list2 <- list(src=x[2,]$V1,
title = x[2,]$V2,
pbset = X[2]$V3)
master_list <- list(list1,list2)
Solution:
Write a for loop that takes each row and creates a
list.
Append this list to a master list.
Example:
y=list(src=as.character(x[i,src),
title=as.character(x[i,]$title),
probes=as.character(x[i,]$probesets))
mastr_list[i]=y
}
problem:
Warning messages:
1: In test[i] = y :
number of items to replace is not a multiple of
replacement length
2: In test[i] = y :
number of items to replace is not a multiple of
replacement length
3: In test[i] = y :
number of items to replace is not a multiple of
replacement length
4: In test[i] = y :
number of items to replace is not a multiple of
replacement length
mastr_list
[[1]]
[1] "positional"
[[2]]
[1] "positional"
[[3]]
[1] "positional"
[[4]]
[1] "positional"
How can I make my master list.
I tried also apply function and result is not exactly
what I desire.
master_list <- apply(x, 1, list)
master_list
[[1]]
[[1]][[1]]
title
src probesets
"chr16q"
"positional" "CMAR,USP10,PSORS8,WT3,SLI1"
[[2]]
[[2]][[1]]
title src
probesets
"chr4p" "positional"
"ATP5I,MHW1,STGD4"
[[3]]
[[3]][[1]]
title src probesets
"chr1q13" "positional" "SCARNA2"
[[4]]
[[4]][[1]]
title src probesets
"chr4q1" "positional" "MORF4LP4"
my final result should look like this: