Page 2 of 2
Re: display values from dataframe into row data
Posted: Tue Oct 01, 2024 4:30 am
by jonathon
hi,
it really does come down to what i've written here:
so there's two important things to check here. the first is that the table contains suitable columns, secondly that the items in the values list have names which match those columns.
so this is going to be a problem, because the items in the list are not named:
values <- as.list(combined_UA_df[2, colNo])
if you go names(values) i think you'll get NULL
instead you could do:
values <- list(xxx=combined_UA_df[2, colNo])
where xxx is the name of the column you want the value to appear in.
if you're not familiar with named lists in R, i can appreciate this can be a bit frustrating to figure out.
jonathon
Re: display values from dataframe into row data
Posted: Wed Oct 02, 2024 7:11 am
by lkchan
Hi, After reading your comments, I relearnt the named dataframe and named list in R.
I name the column in the dataframe
Code: Select all
combined_UA_df <- data.frame(
Item = df_name,
UaValue = UA_values_df
)
output of the combined_UA_df
Item UaValue
1 Q1 0
2 Q2 0
3 Q3 0
4 Q4 0
Here is the latest code
Code: Select all
for (i in 1:nrow(combined_UA_df)) {
values <-combined_UA_df$UaValue[i])
table1$setRow(rowNo = 3, values)
}
table1$setRow(rowNo = 3, list(var = paste("Universal Agreement (UA)")))
the table1 row3 is still not populated.
PS: I feel like singing "let it go"
Re: display values from dataframe into row data
Posted: Thu Oct 03, 2024 12:09 am
by jonathon
hi,
if you check the value of the values list, you'll see that its elements are not named.
for example:
Code: Select all
df <- data.frame(Item=c('Q1', 'Q2', 'Q3', 'Q4'), 'UaValue'=c(0, 0, 0, 0))
values <- df$UaValue[1]
names(values)
you'll see that names(values) will return NULL. here are some different ways you can do it, such that the list elements are named:
Code: Select all
df <- data.frame(Item=c('Q1', 'Q2', 'Q3', 'Q4'), 'UaValue'=c(0, 0, 0, 0))
values <- list(UaValue=df$UaValue[1])
names(values)
Code: Select all
df <- data.frame(Item=c('Q1', 'Q2', 'Q3', 'Q4'), 'UaValue'=c(0, 0, 0, 0))
values <- df[1,'UaValue',drop=FALSE]
names(values)
the last thing, you just need to check that you have a column defined in your .r.yaml for this table, with the name UaValue.
cheers
jonathon
Re: display values from dataframe into row data
Posted: Mon Oct 07, 2024 8:23 am
by lkchan
Hi Sir
I finally solve the UA_values. I change the table to vertical and follow your advice to declare column in r.yaml.
Code: Select all
deps_df <- data.frame(Value = character(), stringsAsFactors = FALSE)
for (item in self$options$dep){
deps_df <- rbind(deps_df, data.frame(Value = paste(item)))
}
combined_score_df <- cbind(deps_df, expAgrSum_df, I_CVI_values_df, UA_values_df)
table1 <- self$results$scoreTable2
for(rowNo in 1:nrow(combined_score_df)){
table1$addRow(rowNo, list(
Item = rowNo,
eA = combined_score_df$expAgrSum_df[rowNo],
iCvi = combined_score_df$I_CVI_values_df[rowNo],
uA = combined_score_df$UA_values_df[rowNo]
))
}
When I want to call Item = combined_scaore_df$deps_df[rowNo], it is not display.
this is the r.yaml code
Code: Select all
- name: scoreTable2
title: Score Table
type: Table
rows: 0
columns:
- name: Item
title: Item
type: text
- name: eA
title: 'Experts in Agreement'
type: number
- name: iCvi
title: 'I-CVI'
type: number
- name: uA
title: 'UA'
type: number
where did I went wrong?
Re: display values from dataframe into row data
Posted: Mon Oct 07, 2024 8:40 am
by jonathon
i wonder if you don't need:
Code: Select all
for(rowNo in 1:nrow(combined_score_df)){
table1$addRow(rowNo, list(
Item = combined_score_df$Value[rowNo],
eA = combined_score_df$expAgrSum_df[rowNo],
iCvi = combined_score_df$I_CVI_values_df[rowNo],
uA = combined_score_df$UA_values_df[rowNo]
))
}
if that doesn't work, we'll need to know the value of combined_score_df
cheers
jonathon
Re: display values from dataframe into row data
Posted: Tue Oct 08, 2024 1:23 am
by lkchan
FINALLY IT WORK
Thank you very much for your patience in guiding.
Terima Kasih banyak banyak (Malay language)
Re: display values from dataframe into row data
Posted: Tue Oct 08, 2024 1:33 am
by jonathon
no problem. my pleasure.
hopefully this will build your confidence going forward.
cheers
jonathon